def simple_statistics(verbose=False): display_func = _util.display_func(verbose) print_func = _util.print_func(verbose) a = af.randu(5, 5) b = af.randu(5, 5) w = af.randu(5, 1) display_func(af.mean(a, dim=0)) display_func(af.mean(a, weights=w, dim=0)) print_func(af.mean(a)) print_func(af.mean(a, weights=w)) display_func(af.var(a, dim=0)) display_func(af.var(a, isbiased=True, dim=0)) display_func(af.var(a, weights=w, dim=0)) print_func(af.var(a)) print_func(af.var(a, isbiased=True)) print_func(af.var(a, weights=w)) display_func(af.stdev(a, dim=0)) print_func(af.stdev(a)) display_func(af.var(a, dim=0)) display_func(af.var(a, isbiased=True, dim=0)) print_func(af.var(a)) print_func(af.var(a, isbiased=True)) display_func(af.median(a, dim=0)) print_func(af.median(w)) print_func(af.corrcoef(a, b))
def simple_statistics(verbose=False): display_func = _util.display_func(verbose) print_func = _util.print_func(verbose) a = af.randu(5, 5) b = af.randu(5, 5) w = af.randu(5, 1) display_func(af.mean(a, dim=0)) display_func(af.mean(a, weights=w, dim=0)) print_func(af.mean(a)) print_func(af.mean(a, weights=w)) display_func(af.var(a, dim=0)) display_func(af.var(a, isbiased=True, dim=0)) display_func(af.var(a, weights=w, dim=0)) print_func(af.var(a)) print_func(af.var(a, isbiased=True)) print_func(af.var(a, weights=w)) mean, var = af.meanvar(a, dim=0) display_func(mean) display_func(var) mean, var = af.meanvar(a, weights=w, bias=af.VARIANCE.SAMPLE, dim=0) display_func(mean) display_func(var) display_func(af.stdev(a, dim=0)) print_func(af.stdev(a)) display_func(af.var(a, dim=0)) display_func(af.var(a, isbiased=True, dim=0)) print_func(af.var(a)) print_func(af.var(a, isbiased=True)) display_func(af.median(a, dim=0)) print_func(af.median(w)) print_func(af.corrcoef(a, b)) data = af.iota(5, 3) k = 3 dim = 0 order = af.TOPK.DEFAULT # defaults to af.TOPK.MAX assert (dim == 0) # topk currently supports first dim only values, indices = af.topk(data, k, dim, order) display_func(values) display_func(indices)
def corrcoef(x, y: tp.Optional = None, rowvar: int = 1, bias: bool = False, ddof: tp.Optional[int] = None): """ Return Pearson product-moment correlation coefficients. """ isbiased = bias if ddof and ddof == 0: isbiased = True cov_array = af.cov(x._af_array, isbiased=isbiased, dim=0) std_array = af.stdev(x._af_array, dim=0) if isinstance(std_array, af.Array) and isinstance(cov_array, af.Array): new_array = cov_array / af.matmulNT(std_array, std_array) return ndarray(new_array) elif (isinstance(std_array, af.Array) and not isinstance(cov_array, af.Array)) or \ (not isinstance(std_array, af.Array) and isinstance(cov_array, af.Array)): raise ValueError("error: either both std_array and cov_array must be " "arrayfire arrays or none of them") else: return cov_array / std_array * std_array
def simple_statistics(verbose=False): display_func = _util.display_func(verbose) print_func = _util.print_func(verbose) a = af.randu(5, 5) b = af.randu(5, 5) w = af.randu(5, 1) display_func(af.mean(a, dim=0)) display_func(af.mean(a, weights=w, dim=0)) print_func(af.mean(a)) print_func(af.mean(a, weights=w)) display_func(af.var(a, dim=0)) display_func(af.var(a, isbiased=True, dim=0)) display_func(af.var(a, weights=w, dim=0)) print_func(af.var(a)) print_func(af.var(a, isbiased=True)) print_func(af.var(a, weights=w)) display_func(af.stdev(a, dim=0)) print_func(af.stdev(a)) display_func(af.var(a, dim=0)) display_func(af.var(a, isbiased=True, dim=0)) print_func(af.var(a)) print_func(af.var(a, isbiased=True)) display_func(af.median(a, dim=0)) print_func(af.median(w)) print_func(af.corrcoef(a, b)) data = af.iota(5, 3) k = 3 dim = 0 order = af.TOPK.DEFAULT # defaults to af.TOPK.MAX assert(dim == 0) # topk currently supports first dim only values,indices = af.topk(data, k, dim, order) display_func(values) display_func(indices)
def std(a: ndarray, axis: tp.Optional[int] = None, ddof: int = 0) \ -> tp.Union[ndarray, numbers.Number]: """ Compute the standard deviation along the specified axis. """ new_af_array: tp.Optional[tp.Union[ndarray, numbers.Number]] = None if ddof or ddof == 0: new_af_array = af.stdev(a._af_array, dim=axis) elif ddof == 1: new_af_array = af.sqrt(af.var(a._af_array, isbiased=False, dim=axis)) if isinstance(new_af_array, af.Array): return ndarray(new_af_array) else: return new_af_array
import arrayfire as af a = af.randu(5, 5) b = af.randu(5, 5) w = af.randu(5, 1) af.display(af.mean(a, dim=0)) af.display(af.mean(a, weights=w, dim=0)) print(af.mean(a)) print(af.mean(a, weights=w)) af.display(af.var(a, dim=0)) af.display(af.var(a, isbiased=True, dim=0)) af.display(af.var(a, weights=w, dim=0)) print(af.var(a)) print(af.var(a, isbiased=True)) print(af.var(a, weights=w)) af.display(af.stdev(a, dim=0)) print(af.stdev(a)) af.display(af.var(a, dim=0)) af.display(af.var(a, isbiased=True, dim=0)) print(af.var(a)) print(af.var(a, isbiased=True)) af.display(af.median(a, dim=0)) print(af.median(w)) print(af.corrcoef(a, b))
import arrayfire as af a = af.randu(5, 5) b = af.randu(5, 5) w = af.randu(5, 1) af.print_array(af.mean(a, dim=0)) af.print_array(af.mean(a, weights=w, dim=0)) print(af.mean(a)) print(af.mean(a, weights=w)) af.print_array(af.var(a, dim=0)) af.print_array(af.var(a, isbiased=True, dim=0)) af.print_array(af.var(a, weights=w, dim=0)) print(af.var(a)) print(af.var(a, isbiased=True)) print(af.var(a, weights=w)) af.print_array(af.stdev(a, dim=0)) print(af.stdev(a)) af.print_array(af.var(a, dim=0)) af.print_array(af.var(a, isbiased=True, dim=0)) print(af.var(a)) print(af.var(a, isbiased=True)) af.print_array(af.median(a, dim=0)) print(af.median(w)) print(af.corrcoef(a, b))