• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Condition类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.nd4j.linalg.indexing.conditions.Condition的典型用法代码示例。如果您正苦于以下问题:Java Condition类的具体用法?Java Condition怎么用?Java Condition使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Condition类属于org.nd4j.linalg.indexing.conditions包,在下文中一共展示了Condition类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: and

import org.nd4j.linalg.indexing.conditions.Condition; //导入依赖的package包/类
/**
 * And over the whole ndarray given some condition
 *
 * @param n    the ndarray to test
 * @param cond the condition to test against
 * @return true if all of the elements meet the specified
 * condition false otherwise
 */
public static boolean and(final INDArray n, final Condition cond) {
    if (cond instanceof BaseCondition) {
        long val = (long) Nd4j.getExecutioner().exec(new MatchCondition(n, cond), Integer.MAX_VALUE).getDouble(0);

        if (val == n.lengthLong())
            return true;
        else
            return false;

    } else {
        boolean ret = true;
        final AtomicBoolean a = new AtomicBoolean(ret);
        Shape.iterate(n, new CoordinateFunction() {
            @Override
            public void process(int[]... coord) {
                if (a.get())
                    a.compareAndSet(true, a.get() && cond.apply(n.getDouble(coord[0])));
            }
        });

        return a.get();
    }
}
 
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:32,代码来源:BooleanIndexing.java


示例2: or

import org.nd4j.linalg.indexing.conditions.Condition; //导入依赖的package包/类
/**
 * Or over the whole ndarray given some condition, with respect to dimensions
 *
 * @param n    the ndarray to test
 * @param condition the condition to test against
 * @return true if all of the elements meet the specified
 * condition false otherwise
 */
public static boolean[] or(final INDArray n, final Condition condition, int... dimension) {
    if (!(condition instanceof BaseCondition))
        throw new UnsupportedOperationException("Only static Conditions are supported");

    MatchCondition op = new MatchCondition(n, condition);
    INDArray arr = Nd4j.getExecutioner().exec(op, dimension);
    boolean[] result = new boolean[arr.length()];

    for (int i = 0; i < arr.length(); i++) {
        if (arr.getDouble(i) > 0)
            result[i] = true;
        else
            result[i] = false;
    }

    return result;
}
 
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:26,代码来源:BooleanIndexing.java


示例3: condi

import org.nd4j.linalg.indexing.conditions.Condition; //导入依赖的package包/类
@Override
public INDArray condi(Condition condition) {
    INDArray linear = linearView();
    for(int i = 0 ;i < length(); i++) {
        boolean met = condition.apply(linear.getDouble(i));
        linear.putScalar(i,met ? 1 : 0);
    }
    return this;
}
 
开发者ID:wlin12,项目名称:JNN,代码行数:10,代码来源:BaseNDArray.java


示例4: condi

import org.nd4j.linalg.indexing.conditions.Condition; //导入依赖的package包/类
@Override
public IComplexNDArray condi(Condition condition) {
    IComplexNDArray linear = linearView();
    for(int i = 0 ;i < length(); i++) {
        boolean met = condition.apply(linear.getComplex(i));
        IComplexNumber put = Nd4j.createComplexNumber(met ? 1 : 0, 0);
        linear.putScalar(i,put);
    }
    return this;
}
 
开发者ID:wlin12,项目名称:JNN,代码行数:11,代码来源:BaseComplexNDArray.java


示例5: and

import org.nd4j.linalg.indexing.conditions.Condition; //导入依赖的package包/类
/**
 * And
 * @param n
 * @param cond
 * @return
 */
public static boolean and(IComplexNDArray n,Condition cond) {
    boolean ret = true;
    IComplexNDArray linear = n.linearView();
    for(int i = 0; i < linear.length(); i++) {
        ret = ret && cond.apply(linear.getComplex(i));
    }

    return ret;
}
 
开发者ID:wlin12,项目名称:JNN,代码行数:16,代码来源:BooleanIndexing.java


示例6: or

import org.nd4j.linalg.indexing.conditions.Condition; //导入依赖的package包/类
/**
 * Or over the whole ndarray given some condition
 * @param n
 * @param cond
 * @return
 */
public static boolean or(IComplexNDArray n,Condition cond) {
    boolean ret = true;
    IComplexNDArray linear = n.linearView();
    for(int i = 0; i < linear.length(); i++) {
        ret = ret || cond.apply(linear.getComplex(i));
    }

    return ret;
}
 
开发者ID:wlin12,项目名称:JNN,代码行数:16,代码来源:BooleanIndexing.java


示例7: applyWhere

import org.nd4j.linalg.indexing.conditions.Condition; //导入依赖的package包/类
/**
 * Based on the matching elements
 * transform to based on condition to with function function
 * @param to the ndarray to transform
 * @param condition  the condition on transform
 * @param function the function to apply the transform to
 */
public static void applyWhere(INDArray to,Condition condition,Function<Number,Number> function) {
    INDArray linear = to.linearView();
    for(int i = 0; i < linear.linearView().length(); i++) {
        if(linear.data().dataType().equals(DataBuffer.FLOAT)) {
            if (condition.apply(linear.getFloat(i))) {
                linear.putScalar(i, function.apply(linear.getFloat(i)).floatValue());
            }
        }
        else  if(condition.apply(linear.getDouble(i)))
            linear.putScalar(i,function.apply(linear.getDouble(i)).doubleValue());


    }
}
 
开发者ID:wlin12,项目名称:JNN,代码行数:22,代码来源:BooleanIndexing.java


示例8: testAbsValueGreaterThan

import org.nd4j.linalg.indexing.conditions.Condition; //导入依赖的package包/类
@Test
public void testAbsValueGreaterThan() {
    final double threshold = 2;

    Condition absValueCondition = new AbsValueGreaterThan(threshold);
    Function<Number, Number> clipFn = new Function<Number, Number>() {
        @Override
        public Number apply(Number number) {
            System.out.println("Number: " + number.doubleValue());
            return (number.doubleValue() > threshold ? threshold : -threshold);
        }
    };

    Nd4j.getRandom().setSeed(12345);
    INDArray orig = Nd4j.rand(1, 20).muli(6).subi(3); //Random numbers: -3 to 3
    INDArray exp = orig.dup();
    INDArray after = orig.dup();

    for (int i = 0; i < exp.length(); i++) {
        double d = exp.getDouble(i);
        if (d > threshold) {
            exp.putScalar(i, threshold);
        } else if (d < -threshold) {
            exp.putScalar(i, -threshold);
        }
    }

    BooleanIndexing.applyWhere(after, absValueCondition, clipFn);

    System.out.println(orig);
    System.out.println(exp);
    System.out.println(after);

    assertEquals(exp, after);
}
 
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:36,代码来源:BooleanIndexingTest.java


示例9: CompareAndSet

import org.nd4j.linalg.indexing.conditions.Condition; //导入依赖的package包/类
public CompareAndSet(INDArray x, double compare, double set, double eps, Condition condition) {
    super(x);
    this.compare = compare;
    this.set = set;
    this.eps = eps;
    if (condition == null)
        this.mode = 0;
    else
        this.mode = condition.condtionNum();

    init(x, null, x, x.length());
}
 
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:13,代码来源:CompareAndSet.java


示例10: MatchConditionTransform

import org.nd4j.linalg.indexing.conditions.Condition; //导入依赖的package包/类
public MatchConditionTransform(INDArray x, INDArray z, double eps, @NonNull Condition condition) {
    super(x, null, z, z.lengthLong());

    this.compare = condition.getValue();
    this.mode = condition.condtionNum();
    this.eps = eps;

    this.extraArgs = new Object[] {compare, eps, (double) mode};
}
 
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:10,代码来源:MatchConditionTransform.java


示例11: FirstIndex

import org.nd4j.linalg.indexing.conditions.Condition; //导入依赖的package包/类
public FirstIndex(SameDiff sameDiff, SDVariable i_v, int[] dimensions, Condition condition, double compare, double eps, int mode) {
    super(sameDiff, i_v, dimensions);
    this.condition = condition;
    this.compare = compare;
    this.eps = eps;
    this.mode = mode;
}
 
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:8,代码来源:FirstIndex.java


示例12: LastIndex

import org.nd4j.linalg.indexing.conditions.Condition; //导入依赖的package包/类
public LastIndex(SameDiff sameDiff, SDVariable i_v, int[] dimensions, Condition condition, double compare, double eps, int mode) {
    super(sameDiff, i_v, dimensions);
    this.condition = condition;
    this.compare = compare;
    this.eps = eps;
    this.mode = mode;
}
 
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:8,代码来源:LastIndex.java


示例13: MatchCondition

import org.nd4j.linalg.indexing.conditions.Condition; //导入依赖的package包/类
public MatchCondition(INDArray x, double eps, Condition condition) {
    super(x);
    this.compare = condition.getValue();
    this.mode = condition.condtionNum();
    this.eps = eps;

    this.extraArgs = new Object[] {compare, eps, (double) mode};
}
 
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:9,代码来源:MatchCondition.java


示例14: condi

import org.nd4j.linalg.indexing.conditions.Condition; //导入依赖的package包/类
@Override
public INDArray condi(Condition condition) {
    Nd4j.getCompressor().autoDecompress(this);
    INDArray linear = this;
    for (int i = 0; i < length(); i++) {
        boolean met = condition.apply(linear.getDouble(i));
        linear.putScalar(i, met ? 1 : 0);
    }
    return this;
}
 
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:11,代码来源:BaseNDArray.java


示例15: condi

import org.nd4j.linalg.indexing.conditions.Condition; //导入依赖的package包/类
@Override
public IComplexNDArray condi(Condition condition) {
    IComplexNDArray linear = linearView();
    for (int i = 0; i < length(); i++) {
        boolean met = condition.apply(linear.getComplex(i));
        IComplexNumber put = Nd4j.createComplexNumber(met ? 1 : 0, 0);
        linear.putScalar(i, put);
    }
    return this;
}
 
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:11,代码来源:BaseComplexNDArray.java


示例16: applyWhere

import org.nd4j.linalg.indexing.conditions.Condition; //导入依赖的package包/类
/**
 * Based on the matching elements
 * op to based on condition to with function function
 *
 * @param to        the ndarray to op
 * @param condition the condition on op
 * @param function  the function to apply the op to
 */
public static void applyWhere(final INDArray to, final Condition condition,
                final Function<Number, Number> function) {
    // keep original java implementation for dynamic

    Shape.iterate(to, new CoordinateFunction() {
        @Override
        public void process(int[]... coord) {
            if (condition.apply(to.getDouble(coord[0])))
                to.putScalar(coord[0], function.apply(to.getDouble(coord[0])).doubleValue());

        }
    });
}
 
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:22,代码来源:BooleanIndexing.java


示例17: assignIf

import org.nd4j.linalg.indexing.conditions.Condition; //导入依赖的package包/类
/**
 * This method does element-wise assing for 2 equal-sized matrices, for each element that matches Condition
 *
 * @param to
 * @param from
 * @param condition
 */
public static void assignIf(@NonNull INDArray to, @NonNull INDArray from, @NonNull Condition condition) {
    if (!(condition instanceof BaseCondition))
        throw new UnsupportedOperationException("Only static Conditions are supported");

    if (to.lengthLong() != from.lengthLong())
        throw new IllegalStateException("Mis matched length for to and from");

    Nd4j.getExecutioner().exec(new CompareAndSet(to, from, condition));
}
 
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:17,代码来源:BooleanIndexing.java


示例18: replaceWhere

import org.nd4j.linalg.indexing.conditions.Condition; //导入依赖的package包/类
/**
 * This method does element-wise assing for 2 equal-sized matrices, for each element that matches Condition
 *
 * @param to
 * @param from
 * @param condition
 */
public static void replaceWhere(@NonNull INDArray to, @NonNull INDArray from, @NonNull Condition condition) {
    if (!(condition instanceof BaseCondition))
        throw new UnsupportedOperationException("Only static Conditions are supported");

    if (to.lengthLong() != from.lengthLong())
        throw new IllegalStateException("Mis matched length for to and from");

    Nd4j.getExecutioner().exec(new CompareAndReplace(to, from, condition));
}
 
开发者ID:deeplearning4j,项目名称:nd4j,代码行数:17,代码来源:BooleanIndexing.java


示例19: assignIf

import org.nd4j.linalg.indexing.conditions.Condition; //导入依赖的package包/类
public INDArray assignIf(final INDArray arr, final Condition condition) {
    // TODO Auto-generated method stub
    return null;
}
 
开发者ID:optimatika,项目名称:ojAlgo-extensions,代码行数:5,代码来源:ArrayND.java


示例20: cond

import org.nd4j.linalg.indexing.conditions.Condition; //导入依赖的package包/类
public INDArray cond(final Condition condition) {
    // TODO Auto-generated method stub
    return null;
}
 
开发者ID:optimatika,项目名称:ojAlgo-extensions,代码行数:5,代码来源:ArrayND.java



注:本文中的org.nd4j.linalg.indexing.conditions.Condition类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ObjectParentData类代码示例发布时间:2022-05-15
下一篇:
Java SawtoothOscillatorBL类代码示例发布时间:2022-05-15
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap