All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.accelad.math.nilgiri.autodiff.DifferentialVectorFunction Maven / Gradle / Ivy

There is a newer version: 1.16
Show newest version
package com.accelad.math.nilgiri.autodiff;

import java.util.ArrayList;

import java.util.Collection;

import com.accelad.math.nilgiri.AbstractIdentityFactory;
import com.accelad.math.nilgiri.BasicDenseVector;
import com.accelad.math.nilgiri.CommutativeGroup;
import com.accelad.math.nilgiri.Field;


public class DifferentialVectorFunction>
        implements CommutativeGroup>,
        Differential> { // ,
                                                         // VectorDifferential>
                                                         // {

    protected AbstractIdentityFactory m_factory;
    protected BasicDenseVector> m_v;

    public DifferentialVectorFunction(AbstractIdentityFactory i_factory,
            DifferentialFunction... i_v) {
        m_factory = i_factory;
        m_v = new BasicDenseVector>(i_v);
    }

    public DifferentialVectorFunction(AbstractIdentityFactory i_factory,
            Collection> i_v) {
        m_factory = i_factory;
        m_v = new BasicDenseVector>(i_v);
    }

    // protected DifferentialVectorFunction(){
    // }
    protected DifferentialVectorFunction(AbstractIdentityFactory i_factory,
            BasicDenseVector> i_v) {
        m_factory = i_factory;
        m_v = i_v;
    }

    public int size() {
        return m_v.size();
    }

    public DifferentialFunction get(int i) {
        return m_v.get(i);
    }

    public DifferentialVectorFunction diff(Variable i_v) {
        int size = this.size();
        ArrayList> v = new ArrayList>(size);
        for (int i = 0; i < size; i++) {
            v.add(this.get(i).diff(i_v));
        }
        return new DifferentialVectorFunction(m_factory, v);
    }

    public DifferentialFunction dot(DifferentialVectorFunction i_v) {
        int size = this.size();
        if (i_v.size() != size) {
            // throw Error
            return null;
        }
        DifferentialFunction norm = new Zero(m_factory);
        for (int i = 0; i < size; i++) {
            norm = norm.plus(this.get(i).mul(i_v.get(i)));
        }
        return norm;
    }

    public DifferentialVectorFunction negate() {
        return new DifferentialVectorFunction(m_factory, m_v.negate());
    }

    public DifferentialVectorFunction plus(DifferentialVectorFunction i_v) {
        return new DifferentialVectorFunction(m_factory, m_v.plus(i_v.m_v));
    }

    public DifferentialVectorFunction minus(DifferentialVectorFunction i_v) {
        return new DifferentialVectorFunction(m_factory, m_v.minus(i_v.m_v));
    }

    public DifferentialVectorFunction mul(long i_n) {
        return new DifferentialVectorFunction(m_factory, m_v.mul(i_n));
    }

    public DifferentialVectorFunction mul(DifferentialFunction i_v) {
        return new DifferentialVectorFunction(m_factory, m_v.mul(i_v));
    }

    public DifferentialVectorFunction div(DifferentialFunction i_v) {
        return new DifferentialVectorFunction(m_factory, m_v.div(i_v));
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy