Skip to content

Commit

Permalink
Merge pull request #10 from rhyolight/cleanup
Browse files Browse the repository at this point in the history
Cleaning up and doccing
  • Loading branch information
rhyolight authored Jun 24, 2017
2 parents 05a8ffd + a1b172c commit 8bb7213
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 8 deletions.
3 changes: 1 addition & 2 deletions bin/highbrow.bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ class Layer extends Renderable {
}

getNeuronByIndex(index) {
return this.getNeurons().find(n => n.index == index);
return this.getNeurons()[index];
}

getNeuronByXyz(x, y, z) {
Expand Down Expand Up @@ -386,7 +386,6 @@ class Layer extends Renderable {
_buildLayer() {
this._neurons = [];
times(this._config.neuronCount)(i => this._neurons.push(new Neuron({
index: i,
state: NeuronState.inactive,
origin: getXyzFromIndex(i, this._config.dimensions.x, this._config.dimensions.y, this._config.dimensions.z)
}, this)));
Expand Down
47 changes: 47 additions & 0 deletions examples/htm-highbrow-layer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/**
* This interface is used to update cell data within the SpToInputVisualization.
* Once created, use it to update cell values.
* @param {Layer} layer - from Highbrow.
*/
function HtmHighbrowLayer(layer) {
this.layer = layer
this.dimensions = layer.getDimensions()
}

HtmHighbrowLayer.prototype.getX = function() {
return this.dimensions.x
};

HtmHighbrowLayer.prototype.getY = function() {
return this.dimensions.y
};

HtmHighbrowLayer.prototype.getZ = function() {
return this.dimensions.z
};

/**
* Gets the value of the cell given the coordinates.
* @param x (int) x coordinate
* @param y (int) y coordinate
* @param z (int) z coordinate
* @returns {*} whatever value was in the cell
*/
HtmHighbrowLayer.prototype.getCellValue = function(x, y, z) {
let neuronState = this.layer.getNeuronByXyz(x, y, z).state
let out = { state: neuronState }
if (neuronState == "inactive") {
out.color = new THREE.Color('#FFFEEE')
} else {
out.color = new THREE.Color('orange')
}
return out;
};

/**
* Send in one object to update the whole layer state. If the data doesn't match
* the structure of the layer, bad things will probably happen.
*/
HtmHighbrowLayer.prototype.update = function(data) {
this.network.update(data)
};
6 changes: 3 additions & 3 deletions examples/webgl.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

$(function() {
const dimensions = {
x: 10, y: 10, z: 1
x: 100, y: 100, z: 1
}
const simple = {
name: "simple network",
Expand All @@ -42,7 +42,7 @@
animateCells(layer);

// Renders the canvas with empty cells into the DOM and canvas.
cellviz.render({initialDistance: 100});
cellviz.render();

setInterval(function() {
animateCells(layer);
Expand All @@ -51,7 +51,7 @@

function animateCells(layer) {
for (let neuron of layer.getNeurons()) {
if (Math.random() >= 0.5) {
if (Math.random() >= 0.98) {
neuron.activate()
} else {
neuron.deactivate()
Expand Down
25 changes: 22 additions & 3 deletions src/layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,40 @@ class Layer extends Renderable {
}

/**
* Will return a list of {@link Neuron}s in global cell order.
* @override
* @returns {Neuron[]} all the neurons in global cell order
*/
getChildren() {
return this.getNeurons()
}

/**
* Will return a list of {@link Neuron}s in global cell order.
* @override
* @returns {Neuron[]} all the neurons in global cell order
*/
getNeurons() {
return this._neurons
}

/**
* Get {@link Neuron} by global cell index.
* @param {int} index - index of neuron to get
* @returns {Neuron} the neuron at specified index
* @throws {KeyError} if invalid index
*/
getNeuronByIndex(index) {
return this.getNeurons().find(n => n.index == index)
return this.getNeurons()[index]
}

/**
* Get {@link Neuron} by 3D coordinate.
* @param {number} x - x
* @param {number} y - y
* @param {number} z - z
* @returns {Neuron} the neuron at specified index
*/
getNeuronByXyz(x, y, z) {
var dims = this.getDimensions()
let globalIndex = z * dims.x * dims.y
Expand Down Expand Up @@ -108,13 +128,12 @@ class Layer extends Renderable {
}

/*
* Builds out the layer from scratch, using an Z,X,Y structure
* Builds out the layer from scratch.
*/
_buildLayer() {
this._neurons = []
times(this._config.neuronCount) (i =>
this._neurons.push(new Neuron({
index: i,
state: NeuronState.inactive,
origin: getXyzFromIndex(
i,
Expand Down

0 comments on commit 8bb7213

Please sign in to comment.