Skip to content

Instantly share code, notes, and snippets.

@ruskotron
Last active November 16, 2016 10:46
Show Gist options
  • Save ruskotron/39155dfd6f48314f6d1793fdecee05e3 to your computer and use it in GitHub Desktop.
Save ruskotron/39155dfd6f48314f6d1793fdecee05e3 to your computer and use it in GitHub Desktop.
Java style pseudocode for the remedian algorithm
/* Remedian algorithm rework to use matrices rather than discrete arrays
"""The program of Figure 2 can be easily adapted to produce
the remedian curve, by replacing the arrays A l , A2,
A3, and A4 of length 11 by matrices with 11 rows and T
columns. In this way the total storage becomes 44T, whereas
the plain median would have needed 14,641T positions"""
*/
int A[T][11];
int i, j, t, w = 0;
while (w < T) {
if (t == T) {
t=0;
w++;
}
for (j = 0; j < 11; j++) {
A[t][j] = data[i++];
}
A[t+1][j++] = median(A[t]);
if (j == A[t+1].length) {
t++;
j=0;
}
}
remedian = median(A[t]);
System.out.println("Remedian: " + remedian)
/* Java style pseudocode for the remedian algorithm in http://web.ipac.caltech.edu/staff/fmasci/home/astro_refs/Remedian.pdf
CC A PROGRAM FOR THE REMEDIAN
CC ..........................
DIMENSION A1(11),A2(11),A3(11),A4(11)
DO 40 M=l,ll
DO 30 L=l,11
DO 20 K=l,ll
DO 10 J=1,11
I=I+l
10 Al(J)=ENTER(I)
20 A2(K)=FMED(Al)
30 A3(L)=FMED(A2)
40 A4(M)=FMED(A3)
REMED=FMED(A4)
WRITE (*,*) REMED
STOP
END
*/
int A1[11], A2[11], A3[11], A4[11];
int i = 0;
for (m = 0; m < 11; m++) {
for (l = 0; l < 11; l++) {
for (k = 0; k < 11; k++) {
for (j = 0; j < 11; j++) {
A1[j] = data[i++];
}
A2[k] = median(A1);
}
A3[l] = median(A2);
}
A4[m] = median(A3);
}
remedian = median(A4)
System.out.println("Remedian: " + remedian)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment