Skip to content
Snippets Groups Projects
Commit 24dd4052 authored by Elias Pipping's avatar Elias Pipping Committed by Elias Pipping
Browse files

Remove unused octave code

parent cc564534
No related branches found
No related tags found
No related merge requests found
...@@ -21,7 +21,6 @@ LIBS="$DUNE_LIBS" ...@@ -21,7 +21,6 @@ LIBS="$DUNE_LIBS"
AC_CONFIG_FILES([ AC_CONFIG_FILES([
Makefile Makefile
src/Makefile src/Makefile
src/octave/Makefile
doc/Makefile doc/Makefile
doc/doxygen/Makefile doc/doxygen/Makefile
doc/doxygen/Doxyfile doc/doxygen/Doxyfile
......
SUBDIRS = octave
check_PROGRAMS = \ check_PROGRAMS = \
test-gradient-horrible \ test-gradient-horrible \
test-gradient-horrible-logarithmic \ test-gradient-horrible-logarithmic \
......
SUBDIRS =
AM_CPPFLAGS = \
$(DUNE_CPPFLAGS) \
-I$(top_srcdir)
## Octave
MKOCTFILE ?= mkoctfile
OCTAVE ?= octave
OCTAVE_MODULES= duneminimise.oct duneevaluate.oct
.PHONY: run-octave
run-octave: $(OCTAVE_MODULES)
$(OCTAVE) --path $(abs_builddir) --path $(abs_srcdir)
include $(srcdir)/octave.mk
include $(top_srcdir)/am/global-rules
% -*- mode:octave -*-
clear all
close all
if exist('graphics_toolkit','file') graphics_toolkit('fltk') end
A=[
1 0
0 1
];
b=[
1
2.5
];
func = 'S'; % slope 1/100
x = -.1:.005: .4;
y = .9:.005:1.1;
[X, Y] = meshgrid(x,y);
xlabel('x')
ylabel('y')
tic
for i=1:length(y)
in = [ X(i,:); Y(i,:) ];
f(i,:) = duneevaluate(A,b,func, in);
end
clear X Y;
toc
surf(x, y, f)
hold on;
steps = 1100;
vecs = zeros(steps + 1, 2);
diffs = zeros(steps, 2);
vecs(1,:) = [0; 0]; % So that we can always calculate a difference
vecs(2,:) = [0; 1]; % Start
for j = 2:steps+1
vecs(j+1,:) = duneminimise(A,b,func,vecs(j,:));
diffs(j,:) = vecs(j+1,:) - vecs(j,:);
line([vecs(j,1) vecs(j+1,1)], ...
[vecs(j,2) vecs(j+1,2)], ...
[duneevaluate(A,b,func,vecs(j,:)') duneevaluate(A,b,func,vecs(j+1,:)')], ...
'color', 'y');
end
axis tight;
xlabel x;
ylabel y;
hold off;
#include <octave/oct.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <dune/common/shared_ptr.hh>
#include <dune/tectonic/octave/duneoctave.hh>
#include <dune/tectonic/samplefunctional.hh>
#include <cassert>
DEFUN_DLD(duneevaluate, args, nargout, "duneevaluate(A,b,points)\n\
\n\
Evaluate x -> 1/2<Ax,x> - <b,x> + H(|x|) at each point y that is a column vector of A using DUNE\n") {
int const dim = 2;
assert(args.length() == 4);
assert(nargout <= 1);
typedef Dune::SampleFunctional<dim> Functional;
Functional::SmallMatrix A;
Dune::octaveToDune<dim>(args(0).matrix_value(), A);
Functional::SmallVector b;
Dune::octaveToDune<dim>(args(1).vector_value(), b);
Dune::shared_ptr<Functional::NonlinearityType const> phi;
charNDArray bar = args(2).char_array_value();
switch (bar(0)) {
case 'S': {
Dune::NiceFunction const *pre_f = new Dune::SampleFunction<100>();
Dune::shared_ptr<Dune::NiceFunction const> f(pre_f);
phi = Dune::make_shared<Functional::NonlinearityType const>(f);
break;
}
case 's': {
Dune::NiceFunction const *pre_f = new Dune::SampleFunction<2>();
Dune::shared_ptr<Dune::NiceFunction const> f(pre_f);
phi = Dune::make_shared<Functional::NonlinearityType const>(f);
break;
}
case 't': {
Dune::NiceFunction const *pre_f = new Dune::TrivialFunction();
Dune::shared_ptr<Dune::NiceFunction const> f(pre_f);
phi = Dune::make_shared<Functional::NonlinearityType const>(f);
break;
}
default:
assert(false);
}
Functional J(A, b, phi);
Matrix points(args(3).matrix_value());
size_t const columns = points.columns();
RowVector ret(columns);
Functional::SmallVector our_point;
for (size_t i = 0; i < columns; ++i) {
Dune::octaveToDune<dim>(points.column(i), our_point);
ret(i) = J(our_point);
}
return octave_value(ret);
}
#include <octave/oct.h>
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <cassert>
#include <dune/common/shared_ptr.hh>
#include <dune/tnnmg/problem-classes/bisection.hh>
#include <dune/tectonic/octave/duneoctave.hh>
#include <dune/tectonic/samplefunctional.hh>
DEFUN_DLD(duneminimise, args, nargout, "duneminimise(A,b,f,y)\n\
\n\
Make a minimisation step of x -> 1/2<Ax,x> - <b,x> + H(|x|) using DUNE starting at x\n") {
int const dim = 2;
assert(args.length() == 4);
assert(nargout <= 1);
typedef Dune::SampleFunctional<dim> Functional;
Functional::SmallMatrix A;
Dune::octaveToDune<dim>(args(0).matrix_value(), A);
Functional::SmallVector b;
Dune::octaveToDune<dim>(args(1).vector_value(), b);
Dune::shared_ptr<Functional::NonlinearityType const> phi;
charNDArray bar = args(2).char_array_value();
switch (bar(0)) {
case 'S': {
Dune::NiceFunction const *pre_f = new Dune::SampleFunction<100>();
Dune::shared_ptr<Dune::NiceFunction const> f(pre_f);
phi = Dune::make_shared<Functional::NonlinearityType const>(f);
break;
}
case 's': {
Dune::NiceFunction const *pre_f = new Dune::SampleFunction<2>();
Dune::shared_ptr<Dune::NiceFunction const> f(pre_f);
phi = Dune::make_shared<Functional::NonlinearityType const>(f);
break;
}
case 't': {
Dune::NiceFunction const *pre_f = new Dune::TrivialFunction();
Dune::shared_ptr<Dune::NiceFunction const> f(pre_f);
phi = Dune::make_shared<Functional::NonlinearityType const>(f);
break;
}
default:
assert(false);
}
Functional J(A, b, phi);
ColumnVector start_octave(args(3).vector_value());
Functional::SmallVector start;
Dune::octaveToDune<dim>(start_octave, start);
Bisection const &bisection =
Bisection(0.0, // acceptError: Stop if the search interval has
// become smaller than this number
1.0, // acceptFactor: ?
1e-12, // requiredResidual: ?
true, // fastQuadratic
0); // safety: acceptance factor for inexact minimization
Dune::minimise(J, start, 1, bisection);
Dune::duneToOctave<dim>(start, start_octave);
return octave_value(start_octave);
}
$(OCTAVE_MODULES): %.oct: %.o
$(MKOCTFILE) -o $@ $< -ldunecommon
$(OCTAVE_MODULES:.oct=.o): %.o: %.cc
$(MKOCTFILE) $(DEFS) $(AM_CPPFLAGS) -c -o $@ $<
CLEANFILES = $(OCTAVE_MODULES) $(OCTAVE_MODULES:.oct=.o)
% -*- mode:octave -*-
clear all
close all
if exist('graphics_toolkit','file') graphics_toolkit('fltk') end
A=[
3 1.5
1.5 4
];
b=[
1
2
];
func = 's'; % slope 1/2
x = -50:1:300;
y = -125:1:50;
[X, Y] = meshgrid(x,y);
xlabel('x')
ylabel('y')
tic
for i=1:length(y)
in = [ X(i,:); Y(i,:) ];
f(i,:) = duneevaluate(A,b,func,in);
end
clear X Y;
toc
surf(x, y, f)
hold on;
steps = 10;
vecs = zeros(steps + 1, 2);
diffs = zeros(steps, 2);
vecs(1,:) = [ 0; 0]; % So that we can always calculate a difference
vecs(2,:) = [279; 0]; % Start
for j = 2:steps+1
vecs(j+1,:) = duneminimise(A,b,func,vecs(j,:));
diffs(j,:) = vecs(j+1,:) - vecs(j,:);
line([vecs(j,1) vecs(j+1,1)], ...
[vecs(j,2) vecs(j+1,2)], ...
[duneevaluate(A,b,func,vecs(j,:)') duneevaluate(A,b,func,vecs(j+1,:)')], ...
'color', 'y');
end
axis tight;
xlabel x;
ylabel y;
hold off;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment