Changeset b83f1d6 in tol


Ignore:
Timestamp:
Dec 11, 2009, 10:42:36 AM (17 years ago)
Author:
Víctor de Buen <vdebuen@…>
Branches:
1941-docker-image-to-test, devel, master
Children:
0bb1f94
Parents:
eaa41f7
Message:

Fixing calculation of first derivative

git-svn-id: ​https://www.tol-project.org/svn/tolp/trunk@1795 be4846ae-f051-483a-831f-b64e7d08527f

Location:
tol_pkg/MulVarFunAprox
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • tol_pkg/MulVarFunAprox/DesignC2.Spheric.tol

    reaa41f7 rb83f1d6  
    124124    VMatrix X.lambda.sum = SetSum(X.lambda);
    125125   
    126     Set X.weight = For(1,_.X.maxNeighbour,VMatrix(Real i)
     126    For(1,_.X.maxNeighbour,VMatrix(Real i)
    127127    {
    128128      X.lambda[i] $/ X.lambda.sum
     129    })
     130  };
     131  ///////////////////////////////////////////////////////////////////////////
     132  Set get.X.weight.partial.derivative.1(Set X.dif, Real s)
     133  ///////////////////////////////////////////////////////////////////////////
     134  {
     135    Real m = VRows(X.dif[1]);
     136    Set X.tao = For(1,_.X.maxNeighbour,VMatrix(Real i)
     137    {
     138      VMatrix X.norm2 = RPow(X.dif[i],2)*Rand(_.n,1,1,1);
     139      RPow(X.norm2,0.5)/_.radius
     140    });
     141    Set X.tao2 = For(1,_.X.maxNeighbour,VMatrix(Real i)
     142    {
     143      RPow(X.tao[i],2)
     144    });
     145    Set X.match = For(1,_.X.maxNeighbour,VMatrix(Real i)
     146    {
     147      LE(X.tao[i],Rand(m,1,1,1))
     148    });
     149    Set X.lambda = For(1,_.X.maxNeighbour,VMatrix(Real i)
     150    {
     151      RPow(X.match[i] $* (Rand(m,1,1,1)-X.tao2[i]),4)
     152    });
     153    Set X.lambda.der = For(1,_.X.maxNeighbour,VMatrix(Real i)
     154    {
     155      RPow(X.match[i] $* (Rand(m,1,1,1)-X.tao2[i]),3)$*X.tao[i]/2
     156    });
     157    VMatrix X.lambda.sum = SetSum(X.lambda);
     158    VMatrix X.lambda.sum.2 = RPow(X.lambda.sum,2);
     159    VMatrix X.lambda.der.sum = SetSum(X.lambda.der);
     160    For(1,_.X.maxNeighbour,VMatrix(Real i)
     161    {
     162      (X.lambda.der[i]$*X.lambda.sum-X.lambda[i]$*X.lambda.der.sum)
     163      $/ X.lambda.sum.2
    129164    })
    130165  }
  • tol_pkg/MulVarFunAprox/DesignC2.tol

    reaa41f7 rb83f1d6  
    7373  Real build.border.points(Real void) { False };
    7474  VMatrix closest.reference.index(VMatrix X);
     75  VMatrix match.evaluable(VMatrix X);
    7576  Set get.X.weight(Set X.dif);
    76   VMatrix match.evaluable(VMatrix X);
     77  Set get.X.weight.partial.derivative.1(Set X.dif, Real s);
    7778
    7879  //////////////////////////////////////////////////////////////////////////////
    … …  
    104105
    105106  //////////////////////////////////////////////////////////////////////////////
    106     VMatrix build.obs.eval(VMatrix X, VMatrix X.h, FunRn2R::@BaseC2.Eval eval)
     107    VMatrix build.obs(VMatrix X, VMatrix X.h)
    107108  //////////////////////////////////////////////////////////////////////////////
    108109  {
    109110    Text _MID = "[@DesignC2::build.obs] ";
     111    FunRn2R::@BaseC2.Eval.Function eval =
     112     FunRn2R::@BaseC2.Eval.Function::New(get.base(0));
    110113    Real m = VRows(X);
    111114    WriteLn("TRACE "+_MID+"1 m="<<m);
    … …  
    144147
    145148  //////////////////////////////////////////////////////////////////////////////
    146     VMatrix build.obs(VMatrix X, VMatrix X.h)
     149    VMatrix build.obs.partial.derivative.1(VMatrix X, VMatrix X.h, Real s)
    147150  //////////////////////////////////////////////////////////////////////////////
    148151  {
    149152    FunRn2R::@BaseC2.Eval.Function eval =
    150153     FunRn2R::@BaseC2.Eval.Function::New(get.base(0));
    151     build.obs.eval(X,X.h,eval)
    152   };
    153   //////////////////////////////////////////////////////////////////////////////
    154     VMatrix build.obs.partial.derivative.1(VMatrix X, VMatrix X.h, Real s)
    155   //////////////////////////////////////////////////////////////////////////////
    156   {
    157     FunRn2R::@BaseC2.Eval.Partial.Derivative.1 eval =
     154    FunRn2R::@BaseC2.Eval.Partial.Derivative.1 der =
    158155     FunRn2R::@BaseC2.Eval.Partial.Derivative.1::New(get.base(0), s);
    159     build.obs.eval(X,X.h,eval)
    160   };
    161   //////////////////////////////////////////////////////////////////////////////
    162     VMatrix build.obs.partial.derivative.2(VMatrix X, VMatrix X.h,
    163                                            Real s1, Real s2)
    164   //////////////////////////////////////////////////////////////////////////////
    165   {
    166     FunRn2R::@BaseC2.Eval.Partial.Derivative.2 eval =
    167      FunRn2R::@BaseC2.Eval.Partial.Derivative.2::New(get.base(0), s1, s2);
    168     build.obs.eval(X,X.h,eval)
    169   };
    170   //////////////////////////////////////////////////////////////////////////////
    171     VMatrix build.obs.partial.integrate.1(VMatrix X, VMatrix X.h, Real s)
    172   //////////////////////////////////////////////////////////////////////////////
    173   {
    174     FunRn2R::@BaseC2.Eval.Partial.Integrate.1 eval =
    175      FunRn2R::@BaseC2.Eval.Partial.Integrate.1::New(get.base(0), s);
    176     build.obs.eval(X,X.h,eval)
    177   };
     156    Text _MID = "[@DesignC2::build.obs.partial.derivative.1] ";
     157    FunRn2R::@BaseC2.Eval.Function eval =
     158     FunRn2R::@BaseC2.Eval.Function::New(get.base(0));
     159    Real m = VRows(X);
     160    WriteLn("TRACE "+_MID+"1 m="<<m);
     161    If(!m, Rand(0,_.N,0,0), {
     162    WriteLn("TRACE "+_MID+"2");
     163    WriteLn("TRACE "+_MID+"3");
     164    VMatrix X.j=DifEq(1/(1-B),Rand(m,1,1,1));
     165    WriteLn("TRACE "+_MID+"4");
     166    Set X.dif = For(1,_.X.maxNeighbour,VMatrix(Real i)
     167    {
     168      Set X.h.i = VCol2Set(SubCol(X.h,[[i]]));
     169      X - SubRow(_.Y,X.h.i)
     170    });
     171    WriteLn("TRACE "+_MID+"5");
     172    Set X.weight = get.X.weight(X.dif);
     173    Set X.weight.der = get.X.weight.partial.derivative.1(X.dif,s);
     174    WriteLn("TRACE "+_MID+"6");
     175    Matrix QX.triplet = Group("ConcatRows", For(1,_.X.maxNeighbour,Matrix(Real i)
     176    {
     177      VMatrix w.i = X.weight[i];
     178      Set sel.rows = MatQuery::SelectMatch(NE(Drop(Abs(w.i),1.E-15),w.i*0));
     179      VMatrix wi = SubRow(w.i,sel.rows);
     180      VMatrix wi.der = SubRow(X.weight.der[i],sel.rows);
     181      VMatrix X.hiK = SubRow((SubCol(X.h,[[i]])-1)*_.K,sel.rows);
     182      VMatrix Xdif.i = SubRow(X.dif[i],sel.rows);
     183      VMatrix X.j.i = SubRow(X.j,sel.rows);
     184      Real eval::upgrade.cache(Xdif.i);
     185      Real der::upgrade.cache(Xdif.i);
     186      Group("ConcatRows", For(1,_.K,Matrix(Real k)
     187      {
     188        VMatrix pk = eval::evaluate.v(k,Xdif.i);
     189        VMatrix pk.der = der::evaluate.v(k,Xdif.i);
     190        VMatrix qk = wi$*pk.der+wi.der$*pk;
     191        VMat2Mat(X.j.i | (X.hiK+k) | qk)
     192      }))
     193    }));
     194    WriteLn("TRACE "+_MID+"7");
     195    Pack(Convert(Triplet(QX.triplet, m, _.N),"Cholmod.R.Sparse"))
     196  })};
     197
    178198  //////////////////////////////////////////////////////////////////////////////
    179199    VMatrix build.border.prior(Real void)
  • tol_pkg/MulVarFunAprox/ModelC2.tol

    reaa41f7 rb83f1d6  
    9898  };
    9999
     100
    100101  //////////////////////////////////////////////////////////////////////////////
    101     VMatrix evaluate.eval(VMatrix X, FunRn2R::@BaseC2.Eval eval)
     102    VMatrix evaluate(VMatrix X)
    102103  //////////////////////////////////////////////////////////////////////////////
    103104  {
    … …  
    108109    Real m.1 = VRows(X.1);
    109110    VMatrix X.1.h = _.design::closest.reference.index(X.1);
    110     VMatrix QX.1 = _.design::build.obs.eval(X.1, X.1.h, eval);
     111    VMatrix QX.1 = _.design::build.obs(X.1, X.1.h);
    111112    VMatrix F.1 = QX.1*_.alpha;
    112113    Matrix triplet.1 = SetCol(X.select)|Rand(m.1,1,1,1)|VMat2Mat(F.1);
    … …  
    115116
    116117  //////////////////////////////////////////////////////////////////////////////
    117     VMatrix evaluate(VMatrix X)
    118   //////////////////////////////////////////////////////////////////////////////
    119   {
    120     FunRn2R::@BaseC2.Eval.Function eval =
    121      FunRn2R::@BaseC2.Eval.Function::New(_.design::get.base(0));
    122     evaluate.eval(X,eval)
    123   };
    124   //////////////////////////////////////////////////////////////////////////////
    125118    VMatrix evaluate.partial.derivative.1(VMatrix X, Real s)
    126119  //////////////////////////////////////////////////////////////////////////////
    127120  {
    128     FunRn2R::@BaseC2.Eval.Partial.Derivative.1 eval =
    129      FunRn2R::@BaseC2.Eval.Partial.Derivative.1::New(_.design::get.base(0), s);
    130     evaluate.eval(X,eval)
    131   };
    132   //////////////////////////////////////////////////////////////////////////////
    133     VMatrix evaluate.partial.derivative.2(VMatrix X,
    134                                           Real s1, Real s2)
    135   //////////////////////////////////////////////////////////////////////////////
    136   {
    137     FunRn2R::@BaseC2.Eval.Partial.Derivative.2 eval =
    138      FunRn2R::@BaseC2.Eval.Partial.Derivative.2::New(_.design::get.base(0), s1, s2);
    139     evaluate.eval(X,eval)
    140   };
    141   //////////////////////////////////////////////////////////////////////////////
    142     VMatrix evaluate.partial.integrate.1(VMatrix X, Real s)
    143   //////////////////////////////////////////////////////////////////////////////
    144   {
    145     FunRn2R::@BaseC2.Eval.Partial.Integrate.1 eval =
    146      FunRn2R::@BaseC2.Eval.Partial.Integrate.1::New(_.design::get.base(0), s);
    147     evaluate.eval(X,eval)
     121    Real m = VRows(X);
     122    VMatrix X.match = _.design::match.evaluable(X);
     123    Set X.select = MatQuery::SelectMatch(X.match);
     124    VMatrix X.1 = SubRow(X,X.select);
     125    Real m.1 = VRows(X.1);
     126    VMatrix X.1.h = _.design::closest.reference.index(X.1);
     127    VMatrix QX.1 = _.design::build.obs.partial.derivative.1(X.1, X.1.h, s);
     128    VMatrix F.1 = QX.1*_.alpha;
     129    Matrix triplet.1 = SetCol(X.select)|Rand(m.1,1,1,1)|VMat2Mat(F.1);
     130    Pack(Convert(Triplet(triplet.1,m,1),"Cholmod.R.Sparse"))
    148131  }
     132
    149133};
    150134
Note: See TracChangeset for help on using the changeset viewer.