comparison src/samer/maths/opt/ConstrainedConjGrad.java @ 0:bf79fb79ee13

Initial Mercurial check in.
author samer
date Tue, 17 Jan 2012 17:50:20 +0000
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:bf79fb79ee13
1 /*
2 * Copyright (c) 2000, Samer Abdallah, King's College London.
3 * All rights reserved.
4 *
5 * This software is provided AS iS and WITHOUT ANY WARRANTY;
6 * without even the implied warranty of MERCHANTABILITY or
7 * FITNESS FOR A PARTICULAR PURPOSE.
8 */
9
10 package samer.maths.opt;
11 import samer.maths.*;
12 import samer.core.*;
13
14 public class ConstrainedConjGrad extends ConjGrad
15 {
16 Constraints C;
17
18 public ConstrainedConjGrad(State s, Constraints c) {
19 super(s); C=c;
20 }
21
22 public void init() {
23 C.negate(S.P1.g,S.h);
24 C.zeroInactive(S.h);
25 S.normh=Util.maxabs(S.h);
26 }
27
28 public void update()
29 {
30 C.sub(dg,S.P2.g,S.P1.g);
31 gg = C.dot(S.P1.g,S.P1.g);
32 dgg = C.dot(dg,S.P2.g);
33
34 C.mul(S.h,dgg/gg);
35 C.sub(S.h,S.P2.g);
36 S.normh=Util.maxabs(S.h);
37
38 double s2=C.dot(S.P2.g,S.h);
39 if (s2>0) {
40 // Shell.trace("steepest descent");
41 C.negate(S.P2.g,S.h);
42 C.zeroInactive(S.h);
43 S.normh=Util.maxabs(S.h);
44 s2=C.dot(S.P2.g,S.h);
45 }
46 S.P2.s=s2;
47 }
48 }