本文整理汇总了Java中eu.riscoss.reasoner.Distribution类的典型用法代码示例。如果您正苦于以下问题:Java Distribution类的具体用法?Java Distribution怎么用?Java Distribution使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Distribution类属于eu.riscoss.reasoner包,在下文中一共展示了Distribution类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: printDistribution
import eu.riscoss.reasoner.Distribution; //导入依赖的package包/类
public static String printDistribution(Distribution dist) {
String printDist = "[ ";
int size = dist.getValues().size();
if(size == 0)
return "[ ]";
if(size == 1)
return "[ " + dist.getValues().get(0) + " ]";
Double[] dblArr = new Double[size];
dist.getValues().toArray(dblArr);
for (int i = 0; i < size; i++) {
printDist += dblArr[i];
if(i < (size - 1)) {
printDist += ", ";
}
}
printDist += " ]";
return printDist;
}
示例2: getDoubleArrayFromDistribution
import eu.riscoss.reasoner.Distribution; //导入依赖的package包/类
/**
* Converts the <code>Distribution</code> object to <code>double[]</code> array.
* @param distribution
* @param chunk (just for reference)
* @return <code>double[]</code> array
*/
private double[] getDoubleArrayFromDistribution(Distribution distribution, Chunk chunk) {
List<Double> values = distribution.getValues();
double[] result = new double[values.size()];
int i = 0; double sum = 0.0;
for (Double d : values) {
result[i++] = d.doubleValue();
sum += d;
}
/* sum != 1.0 */
// seems that we need to introduce less rigorous check here, because of the floating point imprecision
// therefore, lower and upper limits are introduced. 3 decimal places should be sufficient...
if(sum < DIST_SUM_LIMIT_LOW || sum > DIST_SUM_LIMIT_HI) {
throw new ReasonerException(String.format(
"Sum of distribution values [raw: " + sum + ", formatted: %f] is not equal to 1.0 for node: '%s'. "
+ "Check performed within limits: %f - %f", sum, chunk.getId(), DIST_SUM_LIMIT_LOW, DIST_SUM_LIMIT_HI));
}
return result;
}
示例3: invalidCountOfDistributionLevels
import eu.riscoss.reasoner.Distribution; //导入依赖的package包/类
@Test
public void invalidCountOfDistributionLevels() {
engine = new KPARiskAnalysisTool();
engine.loadModel(convertStreamToString(
KPAUnitTesting.class.getResourceAsStream("resources/valid/Timeliness.xdsl")));
for (Chunk c : engine.queryModel(ModelSlice.INPUT_DATA)) {
if ("VAverage_bug_fix_time__days_".equals(c.getId())) {
Field f = engine.getField(c, FieldType.INPUT_VALUE);
System.out.println("Read default distribution: " + f.getValue());
List<Double> values = new ArrayList<Double>();
values.add(0.42);
values.add(0.22);
Distribution distribution = new Distribution();
distribution.setValues(values);
f.setValue(distribution);
this.exception.expect(ReasonerException.class);
engine.setField(c, FieldType.INPUT_VALUE, f);
break;
}
}
}
示例4: distributionSumNotEqualTo1
import eu.riscoss.reasoner.Distribution; //导入依赖的package包/类
/**
* Test checks whether the exception is thrown for distribution sum > 1.0.
*/
@Test
public void distributionSumNotEqualTo1() {
engine.loadModel(convertStreamToString(KPAUnitTesting.class.getResourceAsStream("resources/valid/Timeliness.xdsl")));
Chunk chunk = new Chunk("VHour__When_the_commit_was_made", "Timeliness");
Distribution distribution = new Distribution();
List<Double> values = new ArrayList<>(0);
values.add(0.5);
values.add(0.4);
values.add(0.3);
distribution.setValues(values);
Field field = new Field(DataType.DISTRIBUTION, distribution);
this.exception.expect(ReasonerException.class);
this.engine.setField(chunk, FieldType.INPUT_VALUE, field);
}
示例5: field2RiskData
import eu.riscoss.reasoner.Distribution; //导入依赖的package包/类
RiskData field2RiskData( String id, String target, Field f ) {
RiskData rd = null;
switch( f.getDataType() ) {
case EVIDENCE: {
Evidence e = f.getValue();
rd = new RiskData( id, target, date, RiskDataType.EVIDENCE, e.pack() );
}
break;
case DISTRIBUTION: {
Distribution d = f.getValue();
rd = new RiskData( id, target, date, RiskDataType.DISTRIBUTION, d.pack() );
}
break;
case INTEGER:
case REAL: {
rd = new RiskData( id, target, date, RiskDataType.NUMBER, "" + f.getValue().toString() );
}
break;
case STRING:
break;
case NaN:
default:
break;
}
return rd;
}
示例6: HorizontalDistributionGauge
import eu.riscoss.reasoner.Distribution; //导入依赖的package包/类
public HorizontalDistributionGauge( Distribution d, int w, int h, Color[] colors ) {
super( w, h, BufferedImage.TYPE_INT_ARGB );
if( colors == null ) {
colors = new Color[d.getValues().size()];
for( int i = 0; i < d.getValues().size(); i++ ) {
colors[i] = mkColor( i, d.getValues().size() );
}
}
assert( d.getValues().size() == colors.length );
this.distribution = d;
this.colors = colors;
this.bars = mkBars( d, mleft, mtop, w -(mleft + mright), h -(mtop + mbottom) );
Graphics2D g = (Graphics2D)getGraphics();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
g.setColor( Color.white );
g.fillRect( 0, 0, w, h );
paint( d, g, mleft, mtop, w -(mleft + mright), h -(mtop + mbottom) );
}
示例7: mkBars
import eu.riscoss.reasoner.Distribution; //导入依赖的package包/类
private Rectangle2D[] mkBars( Distribution d, int x, int y, int w, int h ) {
Rectangle2D[] rects = new Rectangle2D[d.getValues().size()];
double step = ((double)h) / d.getValues().size();
for( int i = 0; i < d.getValues().size(); i++ ) {
double val = d.getValues().get( i );
double xi = x; // + w - (val * w); // + (step * i);
double yi = y + (step * i); //+ h - (val * h);
double hi = step -2;
double wi = (val * w);
rects[i] = new Rectangle2D.Double( xi, yi, wi, hi );
}
return rects;
}
示例8: DistributionGauge
import eu.riscoss.reasoner.Distribution; //导入依赖的package包/类
public DistributionGauge( Distribution d, int w, int h, Color[] colors ) {
super( w, h, BufferedImage.TYPE_INT_ARGB );
if( colors == null ) {
colors = new Color[d.getValues().size()];
for( int i = 0; i < d.getValues().size(); i++ ) {
colors[i] = mkColor( i, d.getValues().size() );
}
}
assert( d.getValues().size() == colors.length );
this.distribution = d;
this.colors = colors;
this.bars = mkBars( d, mleft, mtop, w -(mleft + mright), h -(mtop + mbottom) );
Graphics2D g = (Graphics2D)getGraphics();
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
g.setColor( Color.white );
g.fillRect( 0, 0, w, h );
paint( d, g, mleft, mtop, w -(mleft + mright), h -(mtop + mbottom) );
}
示例9: mkBars
import eu.riscoss.reasoner.Distribution; //导入依赖的package包/类
private Rectangle2D[] mkBars( Distribution d, int x, int y, int w, int h ) {
Rectangle2D[] rects = new Rectangle2D[d.getValues().size()];
double step = ((double)w) / d.getValues().size();
for( int i = 0; i < d.getValues().size(); i++ ) {
double val = d.getValues().get( i );
double xi = x + (step * i);
double yi = y + h - (val * h);
double hi = (val * h);
double wi = step -2;
rects[i] = new Rectangle2D.Double( xi, yi, wi, hi );
}
return rects;
}
示例10: getDistributionFromDoubleArray
import eu.riscoss.reasoner.Distribution; //导入依赖的package包/类
public static Distribution getDistributionFromDoubleArray(double[] array) {
List<Double> values = new ArrayList<>();
for (int i = 0; i < array.length; i++) {
values.add(array[i]);
}
Distribution result = new Distribution();
result.setValues(values);
return result;
}
示例11: getDistributionFromDoubleArray
import eu.riscoss.reasoner.Distribution; //导入依赖的package包/类
/**
* Converts the <code>double[]</code> array to <code>Distribution</code> object.
* @param array
* @return <code>Distribution</code>
*/
private Distribution getDistributionFromDoubleArray(double[] array) {
List<Double> values = new ArrayList<>();
for (int i = 0; i < array.length; i++) {
values.add(array[i]);
}
Distribution result = new Distribution();
result.setValues(values);
return result;
}
示例12: confirmEvidenceIsSet
import eu.riscoss.reasoner.Distribution; //导入依赖的package包/类
@Test
public void confirmEvidenceIsSet() {
boolean result = false;
engine = new KPARiskAnalysisTool();
engine.loadModel(convertStreamToString(
KPAUnitTesting.class.getResourceAsStream("resources/valid/Timeliness.xdsl")));
for (Chunk c : engine.queryModel(ModelSlice.INPUT_DATA)) {
if ("VAverage_bug_fix_time__days_".equals(c.getId())) {
Field f = engine.getField(c, FieldType.INPUT_VALUE);
System.out.println("Read default distribution: " + f.getValue());
List<Double> values = new ArrayList<Double>();
values.add(0.42);
values.add(0.22);
values.add(0.16);
values.add(0.11);
values.add(0.09);
Distribution distribution = new Distribution();
distribution.setValues(values);
f.setValue(distribution);
engine.setField(c, FieldType.INPUT_VALUE, f);
Field f2 = engine.getField(c, FieldType.INPUT_VALUE);
System.out.println("Compared distributions before and after setting the evidence: " +
f.getValue() + " - " + f2.getValue() + "\n");
result = compareDistributions((Distribution)f.getValue(), (Distribution)f2.getValue());
break;
}
}
Assert.assertTrue(result);
}
示例13: toJson
import eu.riscoss.reasoner.Distribution; //导入依赖的package包/类
private JsonElement toJson(Distribution d) {
JsonArray a = new JsonArray();
for( double val : d.getValues() ) {
a.add( new JsonPrimitive( "" + val ) );
}
return a;
}
示例14: flatten
import eu.riscoss.reasoner.Distribution; //导入依赖的package包/类
void flatten( Distribution d, int fixedBar ) {
List<Double> v = d.getValues();
double diff = diff( d );
for( int i = 0; i < v.size(); i++ ) {
if( diff == 0 ) break;
if( i == fixedBar ) continue;
double n = v.get( i ) + diff;
if( n < 0 ) n = 0;
if( n > 1 ) n = 1;
v.set( i, n );
diff = diff( d );
}
}
示例15: paint
import eu.riscoss.reasoner.Distribution; //导入依赖的package包/类
private void paint( Distribution d, Graphics2D g, int x, int y, int w, int h ) {
g.setFont( g.getFont().deriveFont( (float)10 ) );
for( int i = 0; i < bars.length; i++ ) {
Rectangle2D r = bars[i];
g.setColor( colors[i] );
g.fill( r );
g.setColor( Color.black );
g.draw( r );
g.drawString( (int)(distribution.getValues().get( i ) * 100) + "%", (float)r.getX() +2, (float)r.getMaxY() -3 );
}
}