Package cc.redberry.core.tensor

Examples of cc.redberry.core.tensor.Product


    public Tensor randomScalarProduct(int size) {
        if (size <= 0)
            throw new IllegalArgumentException("size <= 0");
        if (size == 1)
            return randomScalarSimpleTensor();
        Product product = new Product();
        for (int i = 0; i < size; ++i)
            product.add(randomScalarSimpleTensor());
        return product;
    }
View Full Code Here


    public Tensor randomScalarProduct(int size,int maxSumSize) {
        if (size <= 0)
            throw new IllegalArgumentException("size <= 0");
        if (size == 1)
            return randomScalarSimpleTensor();
        Product product = new Product();
        for (int i = 0; i < size; ++i){
             int randomProductSize = (int) (1 + Math.random() * maxSumSize);
            product.add(randomScalarSimpleTensor());
        }
        return product;
    }
View Full Code Here

        }
    }

    public static Sum[] random2Sums() { //Random sums pair with renamed indices
        Sum[] sums = random2Sums_();
        Product product = new Product(sums);
        RenameConflictingIndices.INSTANCE.transform(product);
        return new Sum[]{
                    (Sum) product.get(0),
                    (Sum) product.get(1)
                };
    }
View Full Code Here

        DescriptiveStatistics timeStats = new DescriptiveStatistics();
        DescriptiveStatistics trysStats = new DescriptiveStatistics();
        int count = 0;
        while (++count < 500) {
            CC.resetTensorNames();
            Product from = rp.nextProduct(15);
            Product target = from.clone();

            long start = System.nanoTime();
            ProductsBijectionsPort port = new ProductsBijectionsPort(from.getContent(), target.getContent());

            int[] bijection;
            boolean good = false;
            int trys = 0;
            OUTER:
View Full Code Here

        DescriptiveStatistics timeStats = new DescriptiveStatistics();
        DescriptiveStatistics trysStats = new DescriptiveStatistics();
        int count = -1;
        while (++count < 100) {
            CC.resetTensorNames();
            Product from = rp.nextProduct(15);
            Product target = from.clone();

            long start = System.nanoTime();
            Tensor[] dataFrom = from.getContent().getDataCopy();
            Tensor[] dataTarget = target.getContent().getDataCopy();
//             if (count == 6)
//                ContractionsGraphDrawer.drawToPngFile(from, "/home/stas/Projects/Durty/", "Huge6");
            if (count == 24)
                ContractionsGraphDrawer.drawToPngFile(from, "/home/stas/Projects/Durty/", "Huge24");
            if (count == 30)
                ContractionsGraphDrawer.drawToPngFile(from, "/home/stas/Projects/Durty/", "Huge30");
            ProductsBijectionsPort port = new ProductsBijectionsPort(from.getContent(), target.getContent());

//            List<int[]> bijections = new ArrayList<>();
            int[] bijection;
            boolean good = false;
            int trys = 0;
View Full Code Here

        DescriptiveStatistics timeStats = new DescriptiveStatistics();
        DescriptiveStatistics trysStats = new DescriptiveStatistics();
        int count = -1;
        while (++count < 10) {
            CC.resetTensorNames();
            Product from = rp.nextProduct(15);
            Product target = from.clone();

//            if (from.getContent().getFullContractionStructure().componentCount != 1) {
//                System.out.println(from.getContent().getFullContractionStructure().componentCount);
//                continue;
//            }

            System.out.println(from.size());

            long start = System.nanoTime();
            ProductsBijectionsPort port = new ProductsBijectionsPort(from.getContent(), target.getContent());

            int[] bijection;
            boolean good = false;
            int trys = 0;
            OUTER:
View Full Code Here

        DescriptiveStatistics timeStats = new DescriptiveStatistics();
        DescriptiveStatistics trysStats = new DescriptiveStatistics();
        int count = 0;
        while (++count < 500) {
            CC.resetTensorNames();
            Product from = rp.nextProduct(15);
            Product target = from.clone();

            long start = System.nanoTime();
            ProductsBijectionsPort port = new ProductsBijectionsPort(from.getContent(), target.getContent());
            Tensor[] dataFrom = from.getContent().getDataCopy();
            Tensor[] dataTarget = target.getContent().getDataCopy();
//            List<int[]> bijections = new ArrayList<>();
            int[] bijection;
            boolean good = false;
            int trys = 0;
            OUTER:
View Full Code Here

            //creating term & processing combinatorics
            Tensor coefficient;
            if (symmetries == null) {
                Symmetrize symmetrize = new Symmetrize(indices,
                        Symmetries.getFullSymmetriesForSortedIndices(totalUpCount, totalLowCount), false);
                Tensor terms = symmetrize.transform(new Product(tCombination));
                if (terms instanceof Sum)
                    for (Tensor t : terms) {
                        result.add(new Product(coefficient = scalarTensorGenerator.next(), t));
                        coefficients.add(coefficient.clone());
                    }
                else {
                    result.add(new Product(coefficient = scalarTensorGenerator.next(), terms));
                    coefficients.add(coefficient.clone());
                }
            } else {
                Symmetrize symmetrize = new Symmetrize(indices,
                        symmetries, true);
                Tensor terms = symmetrize.transform(new Product(tCombination));
                result.add(new Product(coefficient = scalarTensorGenerator.next(), terms));
                coefficients.add(coefficient.clone());
            }
        }
    }
View Full Code Here

            }
            if (res.isEmpty())
                return null;
            return res.equivalent();
        } else if (target instanceof Product) {
            Product product = (Product) target;
            Tensor derivative;
            List<Tensor> resultProducts = new ArrayList<>();
            for (int i = 0; i < product.size(); ++i) {
                derivative = getDerivative(product.getElements().get(i), var);
                if (derivative == null)
                    continue;
                Product clone = (Product) product.clone();
                clone.getElements().remove(i);
                if (!isOne(derivative))
                    clone.add(derivative);
                resultProducts.add(clone.equivalent());
            }
            if (resultProducts.isEmpty())
                return null;
            if (resultProducts.size() == 1)
                return resultProducts.get(0);
            return new Sum(resultProducts);
        } else if (target.getClass() == SimpleTensor.class) {
            SimpleTensor sp = (SimpleTensor) target;
            if (sp.getName() != var.getName())
                return null;
            if (sp.getIndices().size() == 0)
                return TensorNumber.createONE();
            Product kroneckers = new Product();
            Indices targetIndices = sp.getIndices();
            Indices varIndices = var.getIndices();
            for (int i = 0; i < sp.getIndices().size(); ++i)
                kroneckers.add(CC.createMetricOrKronecker(targetIndices.get(i), varIndices.get(i)));
            return kroneckers.equivalent();
        } else if (target.getClass() == TensorField.class) {
            TensorField field = (TensorField) target;
            Tensor[] args = field.getArgs();
            for (int i = 0; i < args.length; ++i)
                if (getDerivative(args[i], var) != null)
                    return Derivative.createFromInversed(target,var);
            return null;
        } else if (target instanceof AbstractScalarFunction) {
            AbstractScalarFunction func = (AbstractScalarFunction) target;
            Tensor der = getDerivative(func.getInnerTensor(), var);
            if (der == null)
                return null;
            if (isOne(der))
                return func.derivative();
            return new Product(func.derivative(), der);
        }
        //TODO get derivative ot derivative
        return null;
    }
View Full Code Here

    @Override
    public PatternSplit split(Tensor tensor) {
        if (tensor instanceof Product) {
            TensorIterator it = tensor.iterator();
            Tensor current;
            Product factored = new Product();
            while (it.hasNext()) {
                current = it.next();
                if (splitPattern.factorOut(current)) {
                    factored.add(current);
                    it.remove();
                }
            }
            if (factored.isEmpty())
                factored.add(TensorNumber.createONE());
            if (((Product) tensor).isEmpty())
                return new PatternSplit(factored, TensorNumber.createONE(), allowDiffStates);
            return new PatternSplit(factored, tensor.equivalent(), allowDiffStates);
        }
        if (tensor instanceof SimpleTensor)
            if (splitPattern.factorOut(tensor)) {
                Product factoredOut = new Product();
                factoredOut.add(tensor);
                return new PatternSplit(factoredOut, allowDiffStates);
            } else {
                Product factoredOut = new Product();
                factoredOut.add(TensorNumber.createONE());
                return new PatternSplit(factoredOut, tensor, allowDiffStates);
            }
        throw new UnsupportedOperationException();
    }
View Full Code Here

TOP

Related Classes of cc.redberry.core.tensor.Product

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.