Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

evjs

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

evjs - npm Package Compare versions

Comparing version 0.1.5 to 0.2.0

6

dist/evjs/evjs.d.ts

@@ -15,6 +15,6 @@ import { Generation, GenerationConfig } from '../generation';

create(seed: any): void;
run(): void;
private evaluate();
private notify();
run(): Promise<void>;
private evaluate;
private notify;
log(str: string): void;
}
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const chalk = require("chalk");
const chalk_1 = __importDefault(require("chalk"));
const generation_1 = require("../generation");

@@ -18,21 +29,25 @@ class EvJs {

run() {
while (this.iteration < this.iterations) {
this.generation = this.generation.evolve();
this.iteration++;
this.evaluate();
}
return __awaiter(this, void 0, void 0, function* () {
while (this.iteration < this.iterations) {
this.generation = this.generation.evolve();
this.iteration++;
yield this.evaluate();
}
});
}
evaluate() {
this.generation.evaluate();
this.generation.sort();
const percentDone = (this.iteration * 100 / this.iterations);
const generation = chalk.red(`GENERATION: ${this.iteration}`);
this.log(generation);
if (this.iteration === 1 || this.iteration === this.iterations || percentDone % (this.config.notification * 100) === 0) {
this.notify();
}
return __awaiter(this, void 0, void 0, function* () {
yield this.generation.evaluate();
this.generation.sort();
const percentDone = (this.iteration * 100 / this.iterations);
const generation = chalk_1.default.red(`GENERATION: ${this.iteration}`);
this.log(generation);
if (this.iteration === 1 || this.iteration === this.iterations || percentDone % (this.config.notification * 100) === 0) {
this.notify();
}
});
}
notify() {
const stats = this.generation.stats;
const statsStr = chalk.blue(JSON.stringify(stats, null, 2));
const statsStr = chalk_1.default.blue(JSON.stringify(stats, null, 2));
this.log(`Stats: ${statsStr}`);

@@ -45,3 +60,3 @@ this.generation.individuals.forEach(individual => {

const data = { fitness, deviation, config, name };
const json = chalk.green(JSON.stringify(data, null, 1));
const json = chalk_1.default.green(JSON.stringify(data, null, 1));
this.log(`Individual: ${json}`);

@@ -48,0 +63,0 @@ });

@@ -12,4 +12,4 @@ import { Individual } from '../individual';

populate(seed: any): void;
add(individual: any): void;
evaluate(): void;
add(individual: Individual): void;
evaluate(): Promise<void>;
sort(): void;

@@ -23,4 +23,4 @@ evolve(): Generation;

};
private getStandardDeviation(items, mean);
private shouldBreed();
private getStandardDeviation;
private shouldBreed;
}
"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });

@@ -46,3 +54,6 @@ const individual_1 = require("../individual");

evaluate() {
this.individuals.forEach(individual => individual.setFitness());
return __awaiter(this, void 0, void 0, function* () {
const individuals = this.individuals.map(individual => individual.setFitness());
yield Promise.all(individuals);
});
}

@@ -49,0 +60,0 @@ sort() {

@@ -13,3 +13,3 @@ import { IndividualConfig } from './individual.model';

constructor(config: IndividualConfig);
setFitness(): void;
setFitness(): Promise<void>;
evolve(): Individual;

@@ -16,0 +16,0 @@ breed(other: Individual): [Individual, Individual];

"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const Chance = require("chance");
const chance = new Chance();
const chance_1 = __importDefault(require("chance"));
const chance = new chance_1.default();
class Individual {

@@ -19,3 +30,5 @@ constructor(config) {

setFitness() {
this.fitness = this.fitnessFn(this.entity);
return __awaiter(this, void 0, void 0, function* () {
this.fitness = yield this.fitnessFn(this.entity);
});
}

@@ -22,0 +35,0 @@ evolve() {

import { Individual } from '../individual';
export declare class Optimize {
max(a: Individual, b: Individual): 1 | -1;
min(a: Individual, b: Individual): 1 | -1;
max(a: Individual, b: Individual): number;
min(a: Individual, b: Individual): number;
}
import { Individual } from '../individual';
declare type Optimize = (best: Individual, curr: Individual) => number;
export declare class Select {
optimize: any;
constructor(optimize: any);
optimize: Optimize;
constructor(optimize: Optimize);
tournament(population: Individual[], n: number): Individual[];
fittest(population: any): any[];
random(population: any): any;
getRandomIndividual(population: any): number;
fittest(population: Individual[]): Individual[];
random(population: Individual[]): Individual[];
getRandomIndividual(population: Individual[]): number;
pair: {
tournament: (population: any, n: any) => Individual[];
fittest: (population: any) => any[];
random: (population: any) => any[];
tournament: (population: Individual[], n: number) => Individual[];
fittest: (population: Individual[]) => Individual[];
random: (population: Individual[]) => Individual[];
};
}
export {};
{
"name": "evjs",
"version": "0.1.5",
"version": "0.2.0",
"description": "Generic genetic/evolution algorithm in JS",

@@ -37,17 +37,19 @@ "main": "dist/index.js",

"dependencies": {
"chalk": "^2.0.1",
"chance": "^1.0.10"
"chalk": "^2.4.2",
"chance": "^1.0.18"
},
"devDependencies": {
"@types/chai": "^4.0.1",
"@types/mocha": "^2.2.41",
"@types/sinon": "^2.3.2",
"chai": "^4.0.2",
"mocha": "^3.4.2",
"nyc": "^11.0.3",
"rimraf": "^2.6.1",
"sinon": "^2.3.6",
"ts-node": "^3.1.0",
"typescript": "^2.4.1"
"@types/chai": "^4.1.7",
"@types/chalk": "^2.2.0",
"@types/chance": "^1.0.1",
"@types/mocha": "^5.2.5",
"@types/sinon": "^7.0.4",
"chai": "^4.2.0",
"mocha": "^5.2.0",
"nyc": "^13.1.0",
"rimraf": "^2.6.3",
"sinon": "^7.2.2",
"ts-node": "^7.0.1",
"typescript": "^3.2.4"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc