Skip to content

Commit

Permalink
Merge branch 'master' into mp_weight_init_objects
Browse files Browse the repository at this point in the history
  • Loading branch information
maxpumperla committed Sep 13, 2017
2 parents 5c084b5 + 42746b0 commit 9e3bdc9
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*-
*
* * Copyright 2015 Skymind,Inc.
* *
* * Licensed 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 org.deeplearning4j.nn.conf.distribution;

import org.nd4j.shade.jackson.annotation.JsonCreator;
import org.nd4j.shade.jackson.annotation.JsonProperty;

/**
* Constant distribution.
*
*/
public class ConstantDistribution extends Distribution {

private double value;

/**
* Create a Constant distribution with given value
*
* @param value the gain
*/
@JsonCreator
public ConstantDistribution(@JsonProperty("value") double value) {
this.value = value;
}

public double getValue() {
return value;
}

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

@Override
public int hashCode() {
final int prime = 31;
int result = 1;
long temp;
temp = Double.doubleToLongBits(value);
result = prime * result + (int) (temp ^ (temp >>> 32));
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
ConstantDistribution other = (ConstantDistribution) obj;
if (Double.doubleToLongBits(value) != Double.doubleToLongBits(other.value))
return false;
return true;
}

public String toString() {
return "ConstantDistribution{value=" + value + "}";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public static org.nd4j.linalg.api.rng.distribution.Distribution createDistributi
OrthogonalDistribution od = (OrthogonalDistribution) dist;
return Nd4j.getDistributions().createOrthogonal(od.getGain());
}
if (dist instanceof ConstantDistribution) {
ConstantDistribution od = (ConstantDistribution) dist;
return Nd4j.getDistributions().createConstant(od.getValue());
}
throw new RuntimeException("unknown distribution type: " + dist.getClass());
}
}

0 comments on commit 9e3bdc9

Please sign in to comment.