<commit_before>/*
 * RuleConn.cpp
 *
 *  Created on: Apr 5, 2009
 *      Author: rasmussn
 */

#include "BiConn.hpp"
#include "src/io/io.h"
#include <assert.h>
#include <string.h>

namespace PV {

BiConn::BiConn(const char * name,
               HyPerCol * hc, HyPerLayer * pre, HyPerLayer * post, int channel,
               int type)
{
   this->connId = hc->numberOfConnections();
   this->name   = strdup(name);
   this->parent = hc;
   this->type = type;

   this->numBundles = 1;

   initialize(NULL, pre, post, channel);

   hc->addConnection(this);
}

int BiConn::outputState(FILE * fp, int kPre)
{
   return 0;

#ifdef DELETEME
   PVSynapseBundle * tasks = this->tasks(kPre, 0);
   PVPatch * pIncr = tasks->tasks[0]->plasticIncr;
   PVPatch * w     = tasks->tasks[0]->weights;
   size_t offset   = tasks->tasks[0]->offset;

   float * M = &pDecr->data[offset];  // STDP decrement variable

   fprintf(fp, "w%d:      M=", kPre);
   stdp_text_write_patch(fp, pIncr, M);
   fprintf(fp, "P=");
   stdp_text_write_patch(fp, pIncr, pIncr->data);  // write the P variable
   fprintf(fp, "w=");
   stdp_text_write_patch(fp, w, w->data);
   fprintf(fp, "\n");
   fflush(fp);
#endif

   return 0;
}

int BiConn::initializeWeights(const char * filename)
{
   if (filename == NULL) {
      PVParams * params = parent->parameters();

      float randomFlag = 0;
      if (params->present(getName(), "randomFlag")) {
         randomFlag = params->value(getName(), "randomFlag");
      }
      if (randomFlag > 0) {
         return initializeRandomWeights(0);
      }

      const float strength = params->value(name, "strength");

      const int xScale = pre->clayer->xScale;
      const int yScale = pre->clayer->yScale;

      const int numPatches = numberOfWeightPatches();
      assert(numPatches == pre->clayer->numNeurons);
      for (int i = 0; i < numPatches; i++) {
         int kPre = i;
         ruleWeights(wPatches[i], kPre, strength);
      }
   }
   else {
      fprintf(stderr, "Initializing weights from a file not implemented for RuleConn\n");
      exit(1);
   } // end if for filename

   return 0;
}

int BiConn::ruleWeights(PVPatch * wp, int kPre, float strength)
{
   pvdata_t * w = wp->data;
<commit_msg>Convert to using arbors.<commit_after>/*
 * RuleConn.cpp
 *
 *  Created on: Apr 5, 2009
 *      Author: rasmussn
 */

#include "BiConn.hpp"
#include "src/io/io.h"
#include <assert.h>
#include <string.h>

namespace PV {

BiConn::BiConn(const char * name,
               HyPerCol * hc, HyPerLayer * pre, HyPerLayer * post, int channel,
               int type)
{
   this->connId = hc->numberOfConnections();
   this->name   = strdup(name);
   this->parent = hc;
   this->type = type;

   this->numAxonalArborLists = 1;

   initialize(NULL, pre, post, channel);

   hc->addConnection(this);
}

int BiConn::outputState(FILE * fp, int kPre)
{
   return 0;

#ifdef DELETEME
   PVSynapseBundle * tasks = this->tasks(kPre, 0);
   PVPatch * pIncr = tasks->tasks[0]->plasticIncr;
   PVPatch * w     = tasks->tasks[0]->weights;
   size_t offset   = tasks->tasks[0]->offset;

   float * M = &pDecr->data[offset];  // STDP decrement variable

   fprintf(fp, "w%d:      M=", kPre);
   stdp_text_write_patch(fp, pIncr, M);
   fprintf(fp, "P=");
   stdp_text_write_patch(fp, pIncr, pIncr->data);  // write the P variable
   fprintf(fp, "w=");
   stdp_text_write_patch(fp, w, w->data);
   fprintf(fp, "\n");
   fflush(fp);
#endif

   return 0;
}

int BiConn::initializeWeights(const char * filename)
{
   if (filename == NULL) {
      PVParams * params = parent->parameters();

      float randomFlag = 0;
      if (params->present(getName(), "randomFlag")) {
         randomFlag = params->value(getName(), "randomFlag");
      }
      if (randomFlag > 0) {
         return initializeRandomWeights(0);
      }

      const float strength = params->value(name, "strength");

      const int xScale = pre->clayer->xScale;
      const int yScale = pre->clayer->yScale;

      const int arbor = 0;
      const int numPatches = numberOfWeightPatches(arbor);
      assert(numPatches == pre->clayer->numNeurons);
      for (int i = 0; i < numPatches; i++) {
         int kPre = i;
         ruleWeights(wPatches[arbor][i], kPre, strength);
      }
   }
   else {
      fprintf(stderr, "Initializing weights from a file not implemented for RuleConn\n");
      exit(1);
   } // end if for filename

   return 0;
}

int BiConn::ruleWeights(PVPatch * wp, int kPre, float strength)
{
   pvdata_t * w = wp->data;

{'fraction_non_alphanumeric': 0.14850166481687013, 'fraction_numerical': 0.008213096559378468, 'mean_word_length': 2.8447098976109215, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 65, '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': '3168471', 'n_tokens_mistral': 1628, 'n_tokens_neox': 1569, 'n_words': 379}