Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function ellipse(width, height, options) {
const matrix = Matrix.zeros(height, width, options);
let yEven = 1 - height % 2;
let xEven = 1 - width % 2;
let a = Math.floor((width - 1) / 2); // horizontal ellipse axe
let b = Math.floor((height - 1) / 2); // vertical ellipse axe
let a2 = a * a;
let b2 = b * b;
if (options.filled) {
for (let y = 0; y <= b; y++) {
let shift = Math.floor(Math.sqrt(a2 - a2 * y * y / b2));
for (let x = a - shift; x <= a; x++) {
matrix.set(b - y, x, 1);
matrix.set(b + y + yEven, x, 1);
matrix.set(b - y, width - x - 1, 1);
matrix.set(b + y + yEven, width - x - 1, 1);
}
}
forward(input) {
this.input = input.slice();
this.input.push(1); // bias
var offs = 0; // offset used to get the current weights in the current perceptron
this.output = Matrix.zeros(1, this.output.length).getRow(0);
for (var i = 0; i < this.output.length; ++i) {
for (var j = 0; j < this.input.length; ++j) {
this.output[i] += this.weights[offs + j] * this.input[j];
}
if (this.isSigmoid)
this.output[i] = sigmoid(this.output[i]);
offs += this.input.length;
}
return this.output.slice();
}
/**
* Created by acastillo on 10/6/15.
*/
'use strict';
var Matrix = require("ml-matrix");
var ridgeRegression = require("../..").KernelRidgeRegression;
var nSamples = 10;
var nVars = 2;
var nSteps = 10, i, j;
var Xs = Matrix.random(nSamples,nVars);
Xs.sub(0.5);
var Ys = Matrix.zeros(nSamples,1);
for(i=0;i
constructor(inputSize, outputSize) {
this.output = Matrix.zeros(1, outputSize).getRow(0);
this.input = Matrix.zeros(1, inputSize + 1).getRow(0); //+1 for bias term
this.deltaWeights = Matrix.zeros(1, (1 + inputSize) * outputSize).getRow(0);
this.weights = randomInitializeWeights(this.deltaWeights.length, inputSize, outputSize);
this.isSigmoid = true;
}
train(error, learningRate, momentum) {
var offs = 0;
var nextError = Matrix.zeros(1, this.input.length).getRow(0);//new Array(this.input.length);
for (var i = 0; i < this.output.length; ++i) {
var delta = error[i];
if (this.isSigmoid)
delta *= sigmoidGradient(this.output[i]);
for (var j = 0; j < this.input.length; ++j) {
var index = offs + j;
nextError[j] += this.weights[index] * delta;
var deltaWeight = this.input[j] * delta * learningRate;
this.weights[index] += this.deltaWeights[index] * momentum + deltaWeight;
this.deltaWeights[index] = deltaWeight;
}
function triangle(width, height, options) {
if (!options.filled) {
throw new Error('Non filled triangle is not implemented');
}
const matrix = Matrix.zeros(height, width, options);
for (let y = 0; y < height; y++) {
let shift = Math.floor((1 - y / height) * width / 2);
for (let x = shift; x < (width - shift); x++) {
matrix.set(y, x, 1);
}
}
return matrix;
}
constructor(inputSize, outputSize) {
this.output = Matrix.zeros(1, outputSize).getRow(0);
this.input = Matrix.zeros(1, inputSize + 1).getRow(0); //+1 for bias term
this.deltaWeights = Matrix.zeros(1, (1 + inputSize) * outputSize).getRow(0);
this.weights = randomInitializeWeights(this.deltaWeights.length, inputSize, outputSize);
this.isSigmoid = true;
}
constructor(inputSize, outputSize) {
this.output = Matrix.zeros(1, outputSize).getRow(0);
this.input = Matrix.zeros(1, inputSize + 1).getRow(0); //+1 for bias term
this.deltaWeights = Matrix.zeros(1, (1 + inputSize) * outputSize).getRow(0);
this.weights = randomInitializeWeights(this.deltaWeights.length, inputSize, outputSize);
this.isSigmoid = true;
}
function rectangle(width, height, options) {
const matrix = Matrix.zeros(height, width);
if (options.filled) {
for (let y = 0; y < height; y++) {
for (let x = 0; x < width; x++) {
matrix.set(y, x, 1);
}
}
} else {
for (let y of [0, height - 1]) {
for (let x = 0; x < width; x++) {
matrix.set(y, x, 1);
}
}
for (let y = 0; y < height; y++) {
for (let x of [0, width - 1]) {
matrix.set(y, x, 1);
}