<commit_before>/*
 * Gratings.cpp
 *
 *  Created on: Oct 23, 2009
 *      Author: <NAME>
 */

#include "Bars.hpp"
#include "../include/pv_common.h"  // for PI
#include "../utils/pv_random.h"
namespace PV {

Bars::Bars(const char * name, HyPerCol * hc) :
   Image(name, hc)
{
#ifdef OBSOLETE
   initialize_data(&loc);
#endif

   // set default params
   // set reference position of bars
   this->position = 0;
   this->lastPosition = position;

   // set bars orientation to default values
   this->orientation = vertical;
   this->lastOrientation = orientation;

   // set switching and moving probabilities
   pSwitch = 0.0;
   pMove = 0.0;

   // check for explicit parameters in params.stdp
   PVParams * params = hc->parameters();
   if (params->present(name, "pMove")) {
      pMove = params->value(name, "pMove");
      //printf("pMove = %f\n", pMove);
   }

   if (params->present(name, "pSwitch")) {
      pSwitch = params->value(name, "pSwitch");
      //printf("pSwitch = %f\n",pSwitch);
   }

   // set parameters that controls position change
   // default values

   random_walk = 1;
   move_forward = 0;
   move_backward = 0;
   random_jump = 0;

   if (params->present(name, "randomWalk")) {
      random_walk = params->value(name, "randomWalk");
      //printf("randomWalk = %d\n", random_walk);
   }

   if (params->present(name, "moveForward")) {
      move_forward = params->value(name, "moveForward");
      //printf("moveForward = %d\n", move_forward);
   }

   if (params->present(name, "moveBackward")) {
      move_backward = params->value(name, "moveBackward");
      //printf("moveBackward = %d\n", move_backward);
   }

   if (params->present(name, "randomJump")) {
      random_jump = params->value(name, "randomJump");
      //printf("randomJump = %d\n", random_jump);
   }


   // set parameters that controls writing of new images
   writeImages = params->value(name, "writeImages",0);

   updateImage(0.0, 0.0);
}

Bars::~Bars()
{
}


/**
 * Description: Clears the image buffer.
 *
 * Arguments: None
 *
 * Return value: 0 if successful, else non-zero.
 */
int Bars::clearImage()
{
   const PVLayerLoc * loc = getLayerLoc();

   const int nx = loc->nx + 2*loc->nb;
   const int ny = loc->ny + 2*loc->nb;
   const int sx = strideX(loc);
   const int sy = strideY(loc);

   for (int iy = 0; iy < ny; iy++) {
      for (int ix = 0; ix < nx; ix++) {
         data[ix*sx + iy*sy] = 0.0;
      }
   }

   return 0;
}


/**
 * NOTES:
 *    - Retina calls updateImage(float time, float dt) and expects a bool variable
 *    in return.
 *    - If true, the image has been changed; if false the image has not been
 * changed.
 *    - If true, the retina also calls copyFromImageBuffer() to copy the Image
 *    data buffer into the V buffer (it also normalizes the V buffer so that V <= 1).
 *    - data values here gets scaled  and modulate the spiking probability of
 *    the neurons in the retina. If data has negative values, we can inadvertently
 *    prevent retina neurons from firing. The data should only take positive values,
 *    unless the background retina spiking probability (which gets modulated by scaled
 *    image data is very high. But this is not right. The neurons should have a minimum
 *    spiking rate - which is given by the background rate - and shouldn't have smaller
 *    rate only larger.
 */
bool Bars::updateImage(float time, float dt)
{
   const PVLayerLoc * loc = getLayerLoc();

   // extended frame
   const int nx = loc->nx + 2*loc->nb;
   const int ny = loc->ny + 2*loc->nb;
   const int sx = strideX(loc);
   const int sy = strideY(loc);

   const int width = 1;
   const int step = 6;
   int x, y;
<commit_msg>Changed to use extended version of strideF, strideX, strideY.<commit_after>/*
 * Gratings.cpp
 *
 *  Created on: Oct 23, 2009
 *      Author: <NAME>
 */

#include "Bars.hpp"
#include "../include/pv_common.h"  // for PI
#include "../utils/pv_random.h"
namespace PV {

Bars::Bars(const char * name, HyPerCol * hc) :
   Image(name, hc)
{
#ifdef OBSOLETE
   initialize_data(&loc);
#endif

   // set default params
   // set reference position of bars
   this->position = 0;
   this->lastPosition = position;

   // set bars orientation to default values
   this->orientation = vertical;
   this->lastOrientation = orientation;

   // set switching and moving probabilities
   pSwitch = 0.0;
   pMove = 0.0;

   // check for explicit parameters in params.stdp
   PVParams * params = hc->parameters();
   if (params->present(name, "pMove")) {
      pMove = params->value(name, "pMove");
      //printf("pMove = %f\n", pMove);
   }

   if (params->present(name, "pSwitch")) {
      pSwitch = params->value(name, "pSwitch");
      //printf("pSwitch = %f\n",pSwitch);
   }

   // set parameters that controls position change
   // default values

   random_walk = 1;
   move_forward = 0;
   move_backward = 0;
   random_jump = 0;

   if (params->present(name, "randomWalk")) {
      random_walk = params->value(name, "randomWalk");
      //printf("randomWalk = %d\n", random_walk);
   }

   if (params->present(name, "moveForward")) {
      move_forward = params->value(name, "moveForward");
      //printf("moveForward = %d\n", move_forward);
   }

   if (params->present(name, "moveBackward")) {
      move_backward = params->value(name, "moveBackward");
      //printf("moveBackward = %d\n", move_backward);
   }

   if (params->present(name, "randomJump")) {
      random_jump = params->value(name, "randomJump");
      //printf("randomJump = %d\n", random_jump);
   }


   // set parameters that controls writing of new images
   writeImages = params->value(name, "writeImages",0);

   updateImage(0.0, 0.0);
}

Bars::~Bars()
{
}


/**
 * Description: Clears the image buffer.
 *
 * Arguments: None
 *
 * Return value: 0 if successful, else non-zero.
 */
int Bars::clearImage()
{
   const PVLayerLoc * loc = getLayerLoc();

   const int nx = loc->nx + 2*loc->nb;
   const int ny = loc->ny + 2*loc->nb;
   const int sx = strideXExtended(loc);
   const int sy = strideYExtended(loc);

   for (int iy = 0; iy < ny; iy++) {
      for (int ix = 0; ix < nx; ix++) {
         data[ix*sx + iy*sy] = 0.0;
      }
   }

   return 0;
}


/**
 * NOTES:
 *    - Retina calls updateImage(float time, float dt) and expects a bool variable
 *    in return.
 *    - If true, the image has been changed; if false the image has not been
 * changed.
 *    - If true, the retina also calls copyFromImageBuffer() to copy the Image
 *    data buffer into the V buffer (it also normalizes the V buffer so that V <= 1).
 *    - data values here gets scaled  and modulate the spiking probability of
 *    the neurons in the retina. If data has negative values, we can inadvertently
 *    prevent retina neurons from firing. The data should only take positive values,
 *    unless the background retina spiking probability (which gets modulated by scaled
 *    image data is very high. But this is not right. The neurons should have a minimum
 *    spiking rate - which is given by the background rate - and shouldn't have smaller
 *    rate only larger.
 */
bool Bars::updateImage(float time, float dt)
{
   const PVLayerLoc * loc = getLayerLoc();

   // extended frame
   const int nx = loc->nx + 2*loc->nb;
   const int ny = loc->ny + 2*loc->nb;
   const int sx = strideXExtended(loc);
   const int sy = strideYExtended(loc);

   const int width = 1;
   const int step = 6;
   int x, y;

{'fraction_non_alphanumeric': 0.13377251949448776, 'fraction_numerical': 0.00887335305189567, 'mean_word_length': 2.8704474505723203, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3667410', 'n_tokens_mistral': 2508, 'n_tokens_neox': 2351, 'n_words': 778}