Package com.github.neuralnetworks.calculation.neuronfunctions

Source Code of com.github.neuralnetworks.calculation.neuronfunctions.ConstantConnectionCalculator

package com.github.neuralnetworks.calculation.neuronfunctions;

import java.util.List;

import com.github.neuralnetworks.architecture.Connections;
import com.github.neuralnetworks.architecture.Layer;
import com.github.neuralnetworks.calculation.ConnectionCalculator;
import com.github.neuralnetworks.calculation.memory.ValuesProvider;
import com.github.neuralnetworks.tensor.Tensor;
import com.github.neuralnetworks.tensor.TensorFactory;

/**
* Basic connection calculator that populates the output with a constant (for bias layers)
*/
public class ConstantConnectionCalculator implements ConnectionCalculator {

    private static final long serialVersionUID = -512468674234271624L;

    private float value;

    public ConstantConnectionCalculator() {
  super();
  this.value = 1;
    }

    public ConstantConnectionCalculator(float value) {
  super();
  this.value = value;
    }

    @Override
    public void calculate(List<Connections> connections, ValuesProvider valuesProvider, Layer targetLayer) {
  Tensor t = TensorFactory.tensor(targetLayer, connections, valuesProvider);
  t.forEach(i -> t.getElements()[i] = value);
    }

    public float getValue() {
        return value;
    }

    public void setValue(float value) {
        this.value = value;
    }
}
TOP

Related Classes of com.github.neuralnetworks.calculation.neuronfunctions.ConstantConnectionCalculator

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.