FLIPS interfaces

From Theory of Measurements Wiki

Jump to: navigation, search

Contents

Precompiled FLIPS interfaces for R and MATLAB

The sources for these interfaces are included in the FLIPS source distribution.

Currently there are precomplied interfaces for Macs (both Intel and PPC) and WindowsXP.

These interfaces use precompiled FLIPS driver flipsengxx (or flipsengxx.exe). The compiled version of this driver is included in the distributions below.

What's new

Version 1.3

  • Bug fixes
  • New FLIPS driver flipseng24
  • Uses new FLIPS-1.1
  • UPDATE 071114: Intel-Mac version seems to work in Leopard (OS X.5)!

RFLIPS interface version 1.2.2

  • Some typos in documentation fixed
  • rflips package structure improved
  • Uses FLIPS-1.0


Version 1.2.1

  • New command flips.rotate (flips_rotate in MATLAB interface) for forcing Givens rotations to the added data. Useful for very large problems.
  • New FLIPS driver flipseng22.
  • Minor bug fixes.

R interface version 1.3

System requirements:

  • Macs
    • Mac OS X.4 (Tiger)
    • R version 2.6.0 (might work also with older versions)
  • WindowsXP
    • R version 2.6.0 (might work also with older versions)

Download


Installation in OS X

  • Untar the downloaded package.
  • Move/copy the file flipseng24 somewhere in your path and make sure that it is executable. For example in Terminal go to the folder rflips_1.3_ppcmac (or rflips_1.3_intelmac) and give the following commands (you need the ability to sudo. Here it is assumed that the directory /usr/local/bin exists and is in PATH):
    sudo cp flipseng24 /usr/local/bin/
    sudo chmod a+x /usr/local/bin/flipseng24
    • You can check the path visible to R by Sys.getenv("PATH"). Note that PATH can be different in GUI and CLI versions of R!
  • Install rflips package in R.
    • This should be done in Terminal since the GUI version of R does not usually have the write access to R's library folder (/Library/Frameworks/R.framework/Resources/library)
      • If you can not start CLI version of R in Terminal, you need to set it up, for example, by giving command
        sudo ln -s /Library/Frameworks/R.framework/R /usr/bin/R
    • Go to the folder rflips_1.3_ppcmac (or rflips_1.3_intelmac) and in that folder give the command:
      sudo R CMD INSTALL rflips
  • In R, load package by
    library(rflips)
  • Some help can be obtained by
    help(rflips)
  • To remove the rflips package from R library, give the command
    sudo R CMD REMOVE rflips

Installation in Windows XP

  • Unzip the downloaded package.
  • Move the file flipseng24.exe somewhere in your path. If you have no idea what the last sentence meant, do the following:
    • Create a new folder for example in C:\Program Files and name it, say, flipseng.
    • Copy/move the file flipseng24.exe into the folder C:\Program Files\flipseng.
    • Add C:\Program Files\flipseng into your PATH environment variable
      • Contor Panel -> System -> Advanced -> Environment Variables
      • Select Variable PATH and click Edit
      • Add into the end of Variable value string ;C:\Program Files\flipseng and click OK -> OK -> OK, and you are done.
  • Start R
  • In the menubar, choose Packages -> Install package(s) from local zip files... Navigate to rflips_1.3_winxp and select file rflips.zip. Click Open and the rflips package should install into R.
  • You can now load the rflips package into R by command library(rflips)
  • Help pages can be accessed via help(rflips) or help(flips)


MATLAB interface version 1.3

System requirements:

  • Macs
    • Mac OS X.4 (Tiger)
    • MATLAB (tested with version 7)
  • WindowsXP
    • MATLAB (tested with version 7)

Download

Installation

  1. Uncompress the downloaded package
  2. Move/copy the folder m_flips into MATLAB's toolbox folder. If you can't/won't to do that you can move/copy the folder where ever you want, but you must modify the file m_flips/@flips/private/flipspath.m accordingly.
  3. Add m_flips into MATLAB's path.
  4. Help can be obtained in MATLAB by
help m_flips

NOTE: If you are upgrading from a older version, remember to rehash MATLAB toolboxes and caches!

Examples

R example

Here we solve a simple deconvolution problem with noisy data. The true solution is convolved with a Hamming window and some (Gaussian) error is added to create a noisy measurement. This data together with the convolution matrix as the theory matrix are then fed into FLIPS. The solution is calculated with and without regularization. Finally, the marginalization of unknowns is demonstrated.


# Load frlips
library(rflips)

# Construct a function for Hamming window
hamming <- function(L)
{
	hamming <- rep(0,L)
	for (n in 0:(L-1))
	{
		hamming[n+1] <- 0.54 - 0.46 * cos(2*pi*n/(L-1))
	}
	return(hamming)
}

# Set up graphics
def.par <- par(no.readonly=TRUE)
layout(matrix(1:6,3,2,byrow=TRUE))

# Construct solution, theory matrix and measurement

# Solution
x<-seq(0,1,len=500)
sol<-abs(100*x*(x-0.2)*(x-0.6)*(x-1))
# Plot solution
plot(x,sol,type="l",main="Solution")

# Construct measurement by convolving solution with Hamming window of length 100.
ham100 <- hamming(100)
meas <- convolve(sol,ham100,type='open')

# Plot measurement
plot(meas,type="l",main="Measurement (no error)")

# Add error to the measurement
noisy.meas <- 0.1 * mean(meas) * rnorm(length(meas)) + meas

# Plot noisy data
plot(noisy.meas,type="l",main="Noisy measurement ")

# Theory matrix
A <- matrix(0,length(meas),500)
for ( i in 1:500)
{
	A[i:(i+99),i] <- ham100
}

# Solve ("dummy boy")
h <- flips.init(500,1,'d')
flips.add(h,A,noisy.meas)
flips.solve(h)
fsol1 <- h$solution
plot(x,h$solution,type="l",main="Dummy boy solution (no regularization)")

# Add regularization
reg.mat <- matrix(0,500,500)
reg.mat[1,1:2] <- c(2,-1)
reg.mat[500,499:500] <- c(-1,2)
for (i in 2:498)
{
	reg.mat[i,(i-1):(i+1)] <- c(-1,2,-1)
}
reg.meas <- rep(0,500)
reg.err <- 0.001

flips.add(h,reg.mat,reg.meas,reg.err)
flips.solve(h)
fsol2 <- h$solution


# Plot regularized solution
plot(x,fsol2,type="l",main="Regularized solution and the real solution")
lines(x,sol,type="l",col="red")

# Initialize new problem, add the same data 
# and regulation and marginalize away
# some of the unknowns
h2 <- flips.init(500,1,'d')
flips.add(h2,A,noisy.meas)
flips.add(h2,reg.mat,reg.meas,reg.err)

# Marginalize fisrt and last 100 unknowns
remove.vec <- c(1:100,401:500)
flips.resize(h2,remove=remove.vec,add=0)

# Solve the resized problem
flips.solve(h2,'rfc')
fsol3 <- h2$solution

# Plot the original and the resized solutions
plot(x,fsol2,type="l",main="Original and resized solutions")
lines(x[101:400],fsol3,type="b",col="red")

# Delete FLIPS files
flips.dispose(h)
flips.dispose(h2)

par(def.par)

MATLAB example

Here we solve a simple deconvolution problem with noisy data. The true solution is convolved with a Hamming window and some (Gaussian) error is added to create a noisy measurement. This data together with the convolution matrix as the theory matrix are then fed into FLIPS. The solution is calculated with and without regularization. Finally, the marginalization of unknowns is demonstrated.


function flips_example()

% Construct solution, theory matrix and measurement

% Solution
x=linspace(0,1,500);
sol=abs(100*x.*(x-0.2).*(x-0.6).*(x-1));

% Plot solution
subplot(3,2,1)
plot(x,sol)
title('Solution')

% Construct measurement by convolving the solution with a Hamming window of
% length 100.
meas = conv(sol,hamming(100));

% plot measurement
subplot(3,2,2)
plot(meas)
title('Measurement (no error)')

% Add noise to the measurement
noisy_meas = 0.1 * mean(meas) * randn(1,length(meas)) + meas;

% plot noisy data
subplot(3,2,3)
plot(noisy_meas)
title('Noisy measurement')

% Construct theory matrix
A = zeros(length(meas),500);
for (i=1:500)
    A(i:(i+99),i) = hamming(100);
end

% Initialize FLIPS object, add data and solve
h = flips;
flips_init(h,500,1,'d');
flips_add(h,A,noisy_meas);
flips_solve(h,'');
fsol1 = flips_get(h,'sol');

subplot(3,2,4)
plot(x,fsol1)
title('Dummy boy solution (no regularization)')

% Add regularization and solve again
reg_mat = 2*eye(500) + -1*diag(ones(499,1),1) + -1*diag(ones(499,1),-1);
reg_meas = zeros(500,1);
reg_err = 0.001;

flips_add(h,reg_mat,reg_meas,reg_err);
flips_solve(h,'');
fsol2 = flips_get(h,'sol');

subplot(3,2,5)
plot(x,fsol2)
hold on
plot(x,sol,'r')
hold off
title('Regularized and true solutions')

% Initialize a new problem, add the same data and regularization, and then
% marginalize away the first and last 100 unknowns
h2=flips;
flips_init(h2,500,1,'d');
flips_add(h2,A,noisy_meas);
flips_add(h2,reg_mat,reg_meas,reg_err);
flips_resize(h2,[1:100 401:500],0);
flips_solve(h2,'');
fsol3 = flips_get(h2,'sol');

subplot(3,2,6)
plot(x,fsol2)
hold on
plot(x(101:400),fsol3,'ro')
hold off
title('Original and resized solutions')


% Delete FLIPS files and reset FLIPS objects
flips_dispose(h);
flips_dispose(h2);


Old versions

rflips v. 1.2.2

m_flips v. 1.2.1

rflips v. 1.2.1

rflips v. 1.0

m_flips v. 1.0

Personal tools