
com.simiacryptus.mindseye.layers.java.SinewaveActivationLayer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mindseye-java Show documentation
Show all versions of mindseye-java Show documentation
Pure Java Neural Networks Components
The newest version!
/*
* Copyright (c) 2019 by Andrew Charneski.
*
* The author licenses this file to you under the
* Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance
* with the License. You may obtain a copy
* of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package com.simiacryptus.mindseye.layers.java;
import com.google.gson.JsonObject;
import com.simiacryptus.mindseye.lang.DataSerializer;
import javax.annotation.Nonnull;
import java.util.Map;
/**
* The type Sinewave activation layer.
*/
@SuppressWarnings("serial")
public final class SinewaveActivationLayer extends SimpleActivationLayer {
private boolean balanced = true;
/**
* Instantiates a new Sinewave activation layer.
*/
public SinewaveActivationLayer() {
}
/**
* Instantiates a new Sinewave activation layer.
*
* @param id the id
*/
protected SinewaveActivationLayer(@Nonnull final JsonObject id) {
super(id);
balanced = id.get("balanced").getAsBoolean();
}
/**
* Is balanced boolean.
*
* @return the boolean
*/
public boolean isBalanced() {
return balanced;
}
/**
* Sets balanced.
*
* @param balanced the balanced
*/
public void setBalanced(boolean balanced) {
this.balanced = balanced;
}
/**
* From json sinewave activation layer.
*
* @param json the json
* @param rs the rs
* @return the sinewave activation layer
*/
@Nonnull
@SuppressWarnings("unused")
public static SinewaveActivationLayer fromJson(@Nonnull final JsonObject json, Map rs) {
return new SinewaveActivationLayer(json);
}
@Nonnull
@Override
public JsonObject getJson(Map resources, DataSerializer dataSerializer) {
@Nonnull final JsonObject json = super.getJsonStub();
json.addProperty("balanced", balanced);
return json;
}
public @SuppressWarnings("unused")
void _free() {
super._free();
}
@Nonnull
public @Override
@SuppressWarnings("unused")
SinewaveActivationLayer addRef() {
return (SinewaveActivationLayer) super.addRef();
}
@Override
protected final void eval(final double x, final double[] results) {
double d = Math.cos(x);
double f = Math.sin(x);
if (!isBalanced()) {
d = d / 2;
f = (f + 1) / 2;
}
results[0] = f;
results[1] = d;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy