Giter Club home page Giter Club logo

belbic4j's Introduction

belbic4j

A simple BELBIC algorithm library for Java language .

How to use

The artifact is in the Maven repository so all you need to do is add it as a dependency in your project.

Maven

 <dependency>
      <groupId>com.github.gustavo053</groupId>
      <artifactId>belbic4j</artifactId>
      <version>1.0.0</version>
</dependency> 

Usage belbic

  • Instance belbic controller:
Belbic belbic = new Belbic();
  • Set the initial parameters for the algorithm:
belbic.initParams(Double alpha, Double beta, Double amygdalaValue, Double orbitofrontalCortexValue, Double weightAmygdala, Double weightOrbitofrontal);

These parameters must be adjusted for each issue (especially alpha and beta).

Generally, the initial values โ€‹โ€‹of the amygdala and orbitofrontal cortex are set to zero so as not to influence learning algorithm.

  • Incremental alpha and beta update:
belbic.setAlpha(Double alpha);
belbic.setBeta(Double beta);
  • Set values for SI block and reward algorithm:
belbic.setSensoryInputValue(Double sensoryInputValue);
belbic.setRewValue(Double rewValue);
  • Run the algorithm and get the control signal:
double u = belbic.run();

Full usage example

import core.Belbic;
import java.util.Arrays;

public class BelbicTestRun {
    //amplifier
    private static double ka = 10;
    private static double taua = 0.1;

    //exciter
    private static double ke = 1;
    private static double taue = 1;

    //generator
    private static double kg = 1;
    private static double taug = 1;

    //sensor
    private static double kr = 1;
    private static double taur = 0.06;

    private static double tMax = 60;
    private static double h = 0.01;
    private static long nPoints = Math.round(tMax / h);

    private static double uMax = 3.3;

    private static double[] vRef = new double[Integer.parseInt(String.valueOf(nPoints))];
    private static double[] vr = new double[Integer.parseInt(String.valueOf(nPoints))];
    private static double[] vf = new double[Integer.parseInt(String.valueOf(nPoints))];
    private static double[] vt = new double[Integer.parseInt(String.valueOf(nPoints))];
    private static double[] vs = new double[Integer.parseInt(String.valueOf(nPoints))];
    private static double[] ve = new double[Integer.parseInt(String.valueOf(nPoints))];

    private static double[] uPlot = new double[Integer.parseInt(String.valueOf(nPoints))];
    private static double[] ePlot = new double[Integer.parseInt(String.valueOf(nPoints))];

    //private double[] tPlot;

    static void amplifier(Integer i, Double u) {
        vr[i] = vr[i - 1] + (h/taua) * (-vr[i - 1]) + ka * u;
    }

    static void exciter(Integer i) {
        vf[i] = vf[i - 1] + (h/taue) * (-vf[i - 1] + ke * vr[i]);
    }

    static void generator(Integer i) {
        vt[i] = vt[i - 1] + (h/taug) * (-vt[i - 1] + kg * vf[i]);
    }

    static Double sensor(Integer i) {
        return vs[i] = vs[i - 1] + (h/taur) * (-vs[i - 1] + kr * vt[i]);
    }

    private static double eant = 0;
    private static double iant = 0;

    static Double pid(Double e) {
        double kp = 3.38;
        double ki = 0.58;
        double kd = 0.63;
        double iMax = 3.3;

        double P = e * kp;
        double I = iant + (ki * h) * (e + eant);
        double D = (kd/h) * (e - eant);

        if (I > iMax) {
            I = iMax;
        } else if (I <= 0) {
            I = 0;
        }

        eant = e;
        iant = I;
        return P + I + D;
    }

    public static void main(String[] args) {
        Arrays.fill(vRef, 2);
        
        //belbic here
        Belbic belbic = new Belbic();
        belbic.initParams(0.45, 0.01, 0.0, 0.0, 0.81, 1.0);

        for (int i = 1; i < nPoints; i++) {
            ve[i] = vRef[i - 1] - vs[i - 1];

            belbic.setAlpha(belbic.getAlpha() * h);
            belbic.setBeta(belbic.getBeta() * h);

            belbic.setSensoryInputValue(pid(ve[i]));
            belbic.setRewValue(Math.abs(ve[i]));

            double u = belbic.run();

            if (u > uMax) {
                u = uMax;
            } else if (u < 0){
                u = 0;
            }

            amplifier(i, u);
            exciter(i);
            generator(i);
            double sensorValue = sensor(i);

            System.out.println(sensorValue);
        }
    }
}

belbic4j's People

Contributors

gustavo053 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

belbic4j's Issues

Create README.md

Create README.md file with example usages and dependency maven.

Implement belbic blocks

Implement the belbic blocks, calling the equations and performing the calculations.

Blocks:

  • Sensory Input;
  • Orbitofrontal Cortex;
  • Sensory Cortex;
  • Amygdala.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.