Advertisement
HighTechDeveloper3

inhibition_example

Jan 14th, 2022
1,489
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.03 KB | None | 0 0
  1. /* * Copyright (c) 2016 Regents of the University of California. All rights reserved.
  2. *
  3. * Redistribution and use in source and binary forms, with or without
  4. * modification, are permitted provided that the following conditions
  5. * are met:
  6. *
  7. * 1. Redistributions of source code must retain the above copyright
  8. *    notice, this list of conditions and the following disclaimer.
  9. *
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. *    notice, this list of conditions and the following disclaimer in the
  12. *    documentation and/or other materials provided with the distribution.
  13. *
  14. * 3. The names of its contributors may not be used to endorse or promote
  15. *    products derived from this software without specific prior written
  16. *    permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  19. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  21. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  22. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  23. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  24. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  25. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  26. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  27. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. *
  30. * *********************************************************************************************** *
  31. * CARLsim
  32. * created by: (MDR) Micah Richert, (JN) Jayram M. Nageswaran
  33. * maintained by:
  34. * (MA) Mike Avery <averym@uci.edu>
  35. * (MB) Michael Beyeler <mbeyeler@uci.edu>,
  36. * (KDC) Kristofor Carlson <kdcarlso@uci.edu>
  37. * (TSC) Ting-Shuo Chou <tingshuc@uci.edu>
  38. * (HK) Hirak J Kashyap <kashyaph@uci.edu>
  39. *
  40. * CARLsim v1.0: JM, MDR
  41. * CARLsim v2.0/v2.1/v2.2: JM, MDR, MA, MB, KDC
  42. * CARLsim3: MB, KDC, TSC
  43. * CARLsim4: TSC, HK
  44. * CARLsim5: HK, JX, KC
  45. * CARLsim6: LN, JX, KC, KW
  46. *
  47. * CARLsim available from http://socsci.uci.edu/~jkrichma/CARLsim/
  48. * Ver 12/31/2016
  49. */
  50.  
  51. // include CARLsim user interface
  52. #include <carlsim.h>
  53.  
  54. // include stopwatch for timing
  55. #include <stopwatch.h>
  56.  
  57. int main() {
  58.     // keep track of execution time
  59.     Stopwatch watch;
  60.    
  61.  
  62.     // ---------------- CONFIG STATE -------------------
  63.    
  64.     // create a network on GPU
  65.     int randSeed = 42;
  66. #ifdef __NO_CUDA__
  67.     int numGPUs = 1;
  68.     CARLsim sim("hello world", CPU_MODE, USER, numGPUs, randSeed);
  69. #else
  70.     //int numGPUs = 2;
  71.     int numGPUs = 1;  // Patch Killian
  72.     CARLsim sim("hello world", GPU_MODE, USER, numGPUs, randSeed);
  73. #endif
  74.  
  75.     // configure the network
  76.     // set up a COBA two-layer network with gaussian connectivity
  77.     Grid3D gridIn(8,8,1); // pre is on a 13x9 grid
  78.     Grid3D gridInh(8,8,1); // post is on a 3x3 grid
  79.     Grid3D gridOut(8,8,1); // post is on a 3x3 grid
  80.  
  81. #ifdef __NO_CUDA__
  82.     int gin=sim.createSpikeGeneratorGroup("input", gridIn, EXCITATORY_NEURON, 0, CPU_CORES);
  83.     int ginh=sim.createGroup("inhib", gridInh, INHIBITORY_NEURON, 0, CPU_CORES);
  84.     int gout=sim.createGroup("output", gridOut, EXCITATORY_NEURON, 0, CPU_CORES);
  85. #else
  86.     int gin = sim.createSpikeGeneratorGroup("input", gridIn, EXCITATORY_NEURON, 0, GPU_CORES);
  87.     int ginh=sim.createGroup("inhib", gridInh, INHIBITORY_NEURON, 0, GPU_CORES);
  88.     int gout = sim.createGroup("output", gridOut, EXCITATORY_NEURON, 0, GPU_CORES);  // Patch Killian
  89. #endif
  90.  
  91.  
  92.     sim.setNeuronParameters(gout, 0.02f, 0.2f, -65.0f, 8.0f); // RS
  93.     sim.setNeuronParameters(ginh, 0.1f, 0.2f, -65.0f, 2.0f); // FS
  94.     sim.connect(gin, gout, "one-to-one", RangeWeight(1.0), 1.0f);
  95.     sim.connect(ginh, gout, "one-to-one", RangeWeight(1), 1.0f);
  96.     sim.connect(gout, ginh, "one-to-one", RangeWeight(1), 1.0f);
  97.     sim.connect(gin, ginh, "one-to-one", RangeWeight(0.00), 1.0f);
  98.  
  99.     sim.setConductances(true);
  100.     // sim.setIntegrationMethod(FORWARD_EULER, 2);
  101.  
  102.     // ---------------- SETUP STATE -------------------
  103.     // build the network
  104.     watch.lap("setupNetwork");
  105.     sim.setupNetwork();
  106.  
  107.     // set some monitors
  108.     sim.setSpikeMonitor(gin,"DEFAULT");
  109.     SpikeMonitor* spk_mon =sim.setSpikeMonitor(gout,"DEFAULT");
  110.     sim.setConnectionMonitor(gin,gout,"DEFAULT");
  111.  
  112.     //setup some baseline input
  113.     PoissonRate in(gridIn.N);
  114.     in.setRates(15.0f);
  115.     sim.setSpikeRate(gin,&in);
  116.  
  117.     //PoissonRate inhib(gridIn.N);
  118.     //inhib.setRates(10.0f);
  119.     //sim.setSpikeRate(ginh,&inhib);
  120.  
  121.     // ---------------- RUN STATE -------------------
  122.     watch.lap("runNetwork");
  123.     spk_mon->startRecording();
  124.  
  125.     // run for a total of 10 seconds
  126.     // at the end of each runNetwork call, SpikeMonitor stats will be printed
  127.     for (int i=0; i<10; i++) {
  128.         sim.runNetwork(1,0, true);
  129.  
  130.         double inhib_level = 4;
  131.  
  132.         for (int i = 0; i < (8*8); i++) {
  133.             sim.setWeight(1,i,i,inhib_level,true);
  134.             sim.setWeight(2,i,i,inhib_level,true);
  135.         }
  136.     }
  137.  
  138.     // print stopwatch summary
  139.     watch.stop();
  140.  
  141.     spk_mon->stopRecording();
  142.  
  143.     printf("\n\n");
  144.     spk_mon->print(false);
  145.    
  146.     return 0;
  147. }
  148.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement