<commit_before>/*
 * destinnetworkalt.h
 *
 *  Created on: Jun 23, 2012
 *      Author: ted
 */

#ifndef DESTINNETWORKALT_H_
#define DESTINNETWORKALT_H_

#include "INetwork.h"
#include "destin.h"
#include "DestinIterationFinishedCallback.h"
#include <stdexcept>
#include <vector>
#include <iostream>

enum SupportedImageWidths {
    W4 = 4,     //1
    W8 = 8,     //2
    W16 = 16,   //3
    W32 = 32,   //4
    W64 = 64,   //5
    W128 = 128, //6
    W256 = 256, //7
    W512 = 512  //8 layers needed
};
#define MAX_IMAGE_WIDTH 512

class destin_network_alt: public INetwork {

private:
    Destin * destin;
    bool training;
    DestinIterationFinishedCallback * callback;
    RunningInfo ri;
    std::vector< std::vector<float> > fakeBeliefs; //stubbed implementation
public:
    destin_network_alt(SupportedImageWidths width, uint layers,
            uint centroid_counts [] ) :
            training(true) {

        uint input_dimensionality = 16;
        bool supported = false;
        uint c, l;
        callback = NULL;

        ri.image_count = -1;
        ri.image_label = -1;
        ri.layer = -1;
        ri.sequence_step = -1;

        //figure out how many layers are needed to support the given
        //image width.
        for (c = 4, l = 1; c <= MAX_IMAGE_WIDTH ; c *= 2, l++) {
            if (c == width) {
                supported = true;
                break;
            }
        }

        if (supported) {
            if (layers == l) {
                int num_movements = 0; //this class does not use movements
                destin = InitDestin(input_dimensionality, layers,
                        centroid_counts, num_movements);
            } else {
                throw std::logic_error("Image width does not match the given number of layers.");
            }
        }else{
            throw std::logic_error("given image width is not supported.");
        }

        //allocate fake beliefs vector
        for(l = 0 ; l < layers ; l++){
            std::vector<float> v;
            fakeBeliefs.push_back(v);
            for(int i = 0 ; i < destin->nBeliefsPerNode[l] ; i++ ){
                v.push_back(0.0);
            }
        }

    }

    virtual ~destin_network_alt() {
        if(destin!=NULL){
            DestroyDestin(destin);
            destin = NULL;
        }
    }

    void doDestin( //run destin with the given input
            float * input_dev //pointer to input memory on device
            ) {
        FormulateBelief(destin, training, input_dev);

        if(this->callback != NULL){
            this->callback->callback(ri, *this );
        }
    }

    void isTraining(bool isTraining) {
        this->training = isTraining;
    }

    bool isTraining() {
        return training;
    }

    void free() {
        DestroyDestin(destin);
        destin = NULL;
    }

    void setIsPOSTraining(bool training) {
        isTraining(training);
    }

    void setIsPSSATraining(bool no_op) {
        //this network doesn't do pssa training
        std::cout << "DestinNetworkAlt setIsPSSATraining called. Currently a noop.\n";
    }

    void setIterationFinishedCallback(DestinIterationFinishedCallback * callback){
        this->callback = callback;
    }

    int getBeliefsPerNode(int layer){
        return destin->nBeliefsPerNode[layer];
    }

    float * getNodeBeliefs(int layer, int row, int col){
        return &(fakeBeliefs[layer][0]); //stub implementation
    }
};

#endif /* DESTINNETWORKALT_H_ */<commit_msg>use the GetNodeFromDestin function instead of stubbed fakebeliefs<commit_after>/*
 * destinnetworkalt.h
 *
 *  Created on: Jun 23, 2012
 *      Author: ted
 */

#ifndef DESTINNETWORKALT_H_
#define DESTINNETWORKALT_H_

#include "INetwork.h"
#include "destin.h"
#include "DestinIterationFinishedCallback.h"
#include <stdexcept>
#include <vector>
#include <iostream>

enum SupportedImageWidths {
    W4 = 4,     //1
    W8 = 8,     //2
    W16 = 16,   //3
    W32 = 32,   //4
    W64 = 64,   //5
    W128 = 128, //6
    W256 = 256, //7
    W512 = 512  //8 layers needed
};
#define MAX_IMAGE_WIDTH 512

class destin_network_alt: public INetwork {

private:
    Destin * destin;
    bool training;
    DestinIterationFinishedCallback * callback;
    RunningInfo ri;
public:
    destin_network_alt(SupportedImageWidths width, uint layers,
            uint centroid_counts [] ) :
            training(true) {

        uint input_dimensionality = 16;
        bool supported = false;
        uint c, l;
        callback = NULL;

        ri.image_count = -1;
        ri.image_label = -1;
        ri.layer = -1;
        ri.sequence_step = -1;

        //figure out how many layers are needed to support the given
        //image width.
        for (c = 4, l = 1; c <= MAX_IMAGE_WIDTH ; c *= 2, l++) {
            if (c == width) {
                supported = true;
                break;
            }
        }

        if (supported) {
            if (layers == l) {
                int num_movements = 0; //this class does not use movements
                destin = InitDestin(input_dimensionality, layers,
                        centroid_counts, num_movements);
            } else {
                throw std::logic_error("Image width does not match the given number of layers.");
            }
        }else{
            throw std::logic_error("given image width is not supported.");
        }

    }

    virtual ~destin_network_alt() {
        if(destin!=NULL){
            DestroyDestin(destin);
            destin = NULL;
        }
    }

    void doDestin( //run destin with the given input
            float * input_dev //pointer to input memory on device
            ) {
        FormulateBelief(destin, training, input_dev);

        if(this->callback != NULL){
            this->callback->callback(ri, *this );
        }
    }

    void isTraining(bool isTraining) {
        this->training = isTraining;
    }

    bool isTraining() {
        return training;
    }

    void free() {
        DestroyDestin(destin);
        destin = NULL;
    }

    void setIsPOSTraining(bool training) {
        isTraining(training);
    }

    void setIsPSSATraining(bool no_op) {
        //this network doesn't do pssa training
        std::cout << "DestinNetworkAlt setIsPSSATraining called. Currently a noop.\n";
    }

    void setIterationFinishedCallback(DestinIterationFinishedCallback * callback){
        this->callback = callback;
    }

    int getBeliefsPerNode(int layer){
        return destin->nBeliefsPerNode[layer];
    }

    float * getNodeBeliefs(int layer, int row, int col){
        return GetNodeFromDestin(destin, layer, row, col)->beliefEuc;
    }
};

#endif /* DESTINNETWORKALT_H_ */
{'fraction_non_alphanumeric': 0.10418535127055306, 'fraction_numerical': 0.01898355754857997, 'mean_word_length': 1.918011338857392, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 26, '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': '6979799', 'n_tokens_mistral': 2163, 'n_tokens_neox': 2024, 'n_words': 532}