FlowerEvolver-WASM JS/WASM API
    Preparing search index...

    Class FEService

    simple wrapper around fe wasm module.

    let fes = new FEService();
    await fes.init(); // must resolve before any other call
    // make a flower with default params
    let flowers = new Array();
    flowers.push(await fes.makeFlower());
    // radius, numLayers, P, bias
    fes.setParams(new FEParams(128, 2, 5.0, -1.0));
    // make a flower with new params.
    flowers.push(await fes.makeFlower());
    flowers.push(await fes.reproduce(flowers[0].genome, flowers[1].genome));
    // mutate child using default mutation rates.
    flowers.push(await fes.mutate(flowers[2].genome))
    Index
    • classifies a flower against the current SOM species classifier: the one embedded in the wasm binary until train()/fineTune()/loadSOM() replace it.

      Parameters

      • genome: string

        stringified json

      • environment: SOMEnvironment = {}

        conditions this flower's stats are computed under; need not match the one the classifier was trained under (see fe::Environment).

      Returns Promise<SpeciesMatch | null>

      the best-matching node and the distance to it, or null if the genome is malformed or its DNA is unusable (not an error; a malformed classifierJson/environment still rejects).

    • classifies a whole batch of flowers in one wasm call (the classifier is parsed once, unlike classify() per flower), e.g. to migrate a saved collection.

      Parameters

      • generationsJson: string

        stringified {"Generation": [...]}, the same shape train()/fineTune() take.

      • environment: SOMEnvironment = {}

        see classify().

      Returns Promise<(SpeciesMatch | null)[]>

      one entry per input flower, in order: the match, or null if that flower's genome is malformed/unusable (not an error).

    • classifies feature vectors from extractFeatures() with the current classifier, no rendering.

      Parameters

      • features: (number[] | null)[]

      Returns Promise<(SpeciesMatch | null)[]>

      one entry per input entry: the match, or null for a null/unusable vector.

    • returns a GLTF string of the flower, it uses the params inside genome.

      Parameters

      • genome: string
      • flowerID: string
      • sex: FlowerSex

      Returns Promise<string>

    • returns a GLTF string of the flower (with normals and emissive textures), it uses the params inside genome.

      Parameters

      • genome: string
      • flowerID: string
      • sex: FlowerSex

      Returns Promise<string>

    • it drawn the flower from the given genome.

      Parameters

      • genome: string

        stringified json

      Returns Promise<Flower>

      flower from the given genome.

    • it drawns the petal layer from the given genome.(no stem)

      Parameters

      • genome: string

        stringified json

      • layer: number

        layer to draw

      Returns Promise<Flower>

      flower - petal from specified layer

    • it drawns the petals from the given genome. (no stem)

      Parameters

      • genome: string

        stringified json

      Returns Promise<Flower>

      flower petals

    • measures how well the current classifier fits a batch of flowers: mean quantization error plus how the flowers spread over the nodes. Look at both when judging convergence, the error can look flat while the load is still being redistributed.

      Parameters

      • generationsJson: string

        stringified {"Generation": [...]}.

      • environment: SOMEnvironment = {}

        see classify().

      Returns Promise<SOMEvaluation>

      if no flower in the batch is usable.

    • evaluate() over feature vectors from extractFeatures() (null entries are dropped).

      Parameters

      • features: (number[] | null)[]

      Returns Promise<SOMEvaluation>

      if no vector is usable.

    • extracts the feature vector of every flower of a batch, once. Rendering is the expensive part of classifying, evaluating or fine-tuning and wasm calls keep no state, so a caller running several steps over the same flowers (e.g. one fine-tuning epoch per call, to show progress) extracts once and passes the vectors (about 1.4 KB as JSON against ~17 KB for a genome) to classifyFeatures()/ evaluateFeatures()/fineTuneFeatures(). Hold them for the length of such a run, not with the stored flowers.

      Parameters

      • generationsJson: string

        stringified {"Generation": [...]}.

      • environment: SOMEnvironment = {}

        see classify(); the vectors depend on it.

      Returns Promise<(number[] | null)[]>

      one entry per input flower, in order: its vector, or null if the genome is malformed/unusable.

    • fine-tunes the current classifier (the embedded default, or one trained or loaded earlier) on a new batch and makes the result the current one (see getSOM()).

      Parameters

      • generationsJson: string

        stringified {"Generation": [...]}, see train().

      • environment: SOMEnvironment = {}

        conditions THIS batch was grown under -- not necessarily what the currently-loaded classifier was originally trained under (see fe::Environment).

      • epochs: number = 50

        how many additional epochs to train for.

      • baseLR: number = 0.3

        starting learning rate for this fine-tuning run.

      • baseRadius: number = 1.0

        starting neighborhood radius for this run.

      Returns Promise<void>

    • fineTune() over feature vectors from extractFeatures() (null entries are dropped); replaces the current classifier like fineTune() does. To report progress run ONE decay in steps: call it once per epoch (or per few epochs) with the same baseLR/baseRadius/totalEpochs and epochOffset = epochs done so far.

      Parameters

      • features: (number[] | null)[]
      • epochs: number

        epochs to run in this call.

      • baseLR: number
      • baseRadius: number
      • epochOffset: number = 0

        epochs of the decay already done by earlier calls, 0 for the first.

      • totalEpochs: number = 0

        epochs of the whole decay, 0 means epochOffset + epochs.

      Returns Promise<void>

    • the short git commit hash this wasm binary was built from, or "unknown" for a build outside a git checkout.

      Returns string

    • gets the flower stats.

      Parameters

      • genome: string

        stringified json

      • humidity: number = 0.5

        0.0 to 1.0

      • temperature: number = 20

        degrees, same scale as the returned min/maxTemperature

      • altitude: number = 0

        meters above sea level

      • terrainType: number = 0

        terrain type id

      Returns FlowerStats

    • the current classifier's JSON, for persisting a trained or fine-tuned result. Pure JS state, so it works before init(). "" until train()/fineTune()/loadSOM() has been called, i.e. while the embedded classifier is in use.

      Returns string

      loadSOM to restore a previously-saved one.

    • the classifier embedded in the wasm binary, as-is -- what classify() uses until train()/fineTune()/loadSOM() replace it (see getSOM()).

      Returns string

    • the semver this wasm binary was built from, e.g. "4.0.0". Same value as this package's own package.json "version".

      Returns string

    • getVersion() + "+" + getCommitHash(), e.g. "4.0.0+a1b2c3d".

      Returns string

    • function to load wasm module.

      Returns Promise<void>

    • replaces the current classifier with one supplied directly, e.g. saved earlier via getSOM() or fetched as its own asset. Pure JS state: the JSON is not parsed or validated until the next classify()/fineTune(), so this works before init().

      Parameters

      • classifierJson: string

        stringified FlowerClassifier.toJson()

      Returns void

    • returns a GLTF string of the flower.

      Parameters

      • genome: string
      • flowerID: string
      • sex: FlowerSex

      Returns Promise<string>

      GLTF file string

    • returns a GLTF string of the flower (with normals and emissive textures).

      Parameters

      • genome: string
      • flowerID: string
      • sex: FlowerSex

      Returns Promise<string>

      GLTF file string

    • it makes the petal for the specified layer. (no stem)

      Parameters

      • layer: number

      Returns Promise<Flower>

      flower, only petal in layer

    • it makes a flower with no stem.

      Returns Promise<Flower>

      flower, only petals

    • it makes a simple stem. (no petals)

      Returns Promise<Flower>

      flower, only stem

    • it mutates the given flower genome.

      Parameters

      • original: string

        genome from original flower.

      • addNodeRate: number = 0.2
      • addConnRate: number = 0.3
      • removeConnRate: number = 0.2
      • perturbWeightsRate: number = 0.6
      • enableRate: number = 0.35
      • disableRate: number = 0.3
      • actTypeRate: number = 0.4

      Returns Promise<Flower>

      flower - the new mutated flower

    • it makes a child from two flower genomes.

      Parameters

      • father: string

        genome for father

      • mother: string

        genome for mother

      Returns Promise<Flower>

      flower - child flower

    • sets the parameters for the creation of flowers.

      Parameters

      Returns void

    • trains a fresh SOM species classifier from a whole batch of flower genomes in one wasm call and makes it the current one (see getSOM()).

      Parameters

      • generationsJson: string

        stringified {"Generation": [{"dna":...,"petals":...}, ...]} (the wire format used to move a flower collection between apps); entries that fail feature extraction are skipped and logged, not an error.

      • environment: SOMEnvironment = {}

        conditions this batch was grown under.

      • training: SOMTrainingConfig = {}

        grid size + hyperparameters.

      Returns Promise<void>