bwilk1@umbc.edu
bwilk7.github.io
ITE 374
Office Hours: Tuesday 10:00am and Wednesday 2:30pm or by appointment
Website: http://www.csee.umbc.edu/courses/331/fall15/05/
import pickle
import numpy
import rpy2.robjects.packages as rpackages
import rpy2.robjects.numpy2ri as np2ri
import rpy2.robjects as ro
np2ri.activate()
psych = rpackages.importr('psych')
rawData = pickle.load(open('mturkResults.pkl'))
data = pandas.DataFrame(rawData)
agreementMatrix = numpy.nan_to_num(numpy.corrcoef(data))
numpy.fill_diagonal(agreementMatrix,1)
#Call R function
factors = psych.fa(agreementMatrix,fm='pa')
(2 = 0 +.= T o.| T) / T <- iN
The following examples are taken from http://rosettacode.org/
#include <stdio.h>
#include <math.h>
int main(int argc, char **argv) {
float x[4] = {1,2,3,1e11}, y[4];
int i = 0;
FILE *filePtr;
filePtr = fopen("floatArray","w");
for (i = 0; i < 4; i++) {
y[i] = sqrt(x[i]);
fprintf(filePtr, "%.3g\t%.5g\n", x[i], y[i]);
}
return 0;
}
filename = "file.txt"
x = { 1, 2, 3, 1e11 }
y = { 1, 1.4142135623730951, 1.7320508075688772, 316227.76601683791 };
xprecision = 3;
yprecision = 5;
fstr = "%."..tostring(xprecision).."f ".."%."..tostring(yprecision).."f\n"
fp = io.open( filename, "w+" )
for i = 1, #x do
fp:write( string.format( fstr, x[i], y[i] ) )
end
io.close( fp )
# prepare test data
x = [1, 2, 3, 1e11]
y = x.collect { |xx| Math.sqrt xx }
xprecision = 3
yprecision = 5
# write the arrays
open('sqrt.dat', 'w') do |f|
x.zip(y) { |xx, yy| f.printf("%.*g\t%.*g\n", xprecision, xx, yprecision, yy) }
end
# print the result file
open('sqrt.dat', 'r') { |f| puts f.read }
import java.io.*;
public class FloatArray {
public static void writeDat(String filename, double[] x, double[] y,
int xprecision, int yprecision)
throws IOException {
assert x.length == y.length;
PrintWriter out = new PrintWriter(filename);
for (int i = 0; i < x.length; i++)
out.printf("%."+xprecision+"g\t%."+yprecision+"g\n", x[i], y[i]);
out.close();
}
public static void main(String[] args) {
double[] x = {1, 2, 3, 1e11};
double[] y = new double[x.length];
for (int i = 0; i < x.length; i++)
y[i] = Math.sqrt(x[i]);
try {
writeDat("sqrt.dat", x, y, 3, 5);
} catch (IOException e) {
System.err.println("writeDat: exception: "+e);
}
try {
BufferedReader br = new BufferedReader(new FileReader("sqrt.dat"));
String line;
while ((line = br.readLine()) != null)
System.out.println(line);
} catch (IOException e) { }
}
}
(with-open-file (stream (make-pathname :name "filename") :direction :output)
(let* ((x (make-array 4 :initial-contents '(1 2 3 1e11)))
(y (map 'vector 'sqrt x))
(xprecision 3)
(yprecision 5)
(fmt (format nil "~~,1,~d,,G~~12t~~,~dG~~%" xprecision yprecision)))
(map nil (lambda (a b)
(format stream fmt a b)) x y)))
import System.IO
import Text.Printf
import Control.Monad
writeDat filename x y xprec yprec =
withFile filename WriteMode $ \h ->
-- Haskell's printf doesn't support a precision given as an argument for some reason, so we insert it into the format manually:
let writeLine = hPrintf h $ "%." ++ show xprec ++ "g\t%." ++ show yprec ++ "g\n" in
zipWithM_ writeLine x y
palindrome(Word) :- name(Word,List), reverse(List,List).