Skip to content

Commit de89f7a

Browse files
committed
Initial commit
0 parents  commit de89f7a

File tree

7 files changed

+278
-0
lines changed

7 files changed

+278
-0
lines changed

.github/workflows/ant.yml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
name: Java CI
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
tags: [ 'v*.*' ]
7+
pull_request:
8+
branches: [ master ]
9+
10+
jobs:
11+
test:
12+
strategy:
13+
matrix:
14+
os: [ubuntu-latest, windows-latest, macOS-latest]
15+
java: [ 8 ]
16+
runs-on: ${{ matrix.os }}
17+
steps:
18+
- uses: actions/checkout@v2
19+
- uses: actions/setup-java@v1
20+
with:
21+
java-version: ${{ matrix.java }}
22+
java-package: jdk
23+
- uses: r-lib/actions/setup-r@v1
24+
with:
25+
r-version: 3.6
26+
- if: matrix.os == 'macos-latest'
27+
run: ln -s /Library/Frameworks/R.framework/Versions/3.6 /Library/Frameworks/R.framework/Versions/3.5
28+
- uses: r-lib/actions/setup-pandoc@v1
29+
- run: |
30+
WD=$PWD
31+
cd ..
32+
git clone https://github.com/Funz/funz-profile
33+
cd $WD
34+
shell: bash
35+
- if: matrix.os == 'ubuntu-latest'
36+
run: sudo apt-get -y install libharfbuzz-dev libfribidi-dev libcurl4-openssl-dev
37+
- run: ant -noinput -buildfile build.xml test
38+
id: anttest
39+
continue-on-error: true
40+
- if: steps.anttest.outcome != 'success'
41+
uses: actions/upload-artifact@v2
42+
with:
43+
name: artifacts-${{ matrix.os }}-${{ matrix.java }}
44+
path: |
45+
*.txt
46+
*.log
47+
*.out
48+
*.Rout
49+
*.Rmd
50+
*.md
51+
*.html
52+
- if: steps.anttest.outcome != 'success'
53+
run: exit 1
54+
55+
release:
56+
runs-on: ubuntu-latest
57+
steps:
58+
- uses: actions/checkout@v2
59+
- uses: actions/setup-java@v1
60+
with:
61+
java-version: 1.8
62+
java-package: jdk
63+
- run: |
64+
WD=$PWD
65+
cd ..
66+
git clone https://github.com/Funz/funz-profile
67+
cd $WD
68+
- run: |
69+
ant clean dist
70+
cd dist; zip -r ../algorithm-MyAlgorithm.zip *; cd ..
71+
ant install
72+
zip -r FunzR-MyAlgorithm.zip FunzR-MyAlgorithm
73+
- uses: actions/upload-artifact@v2
74+
with:
75+
path: dist
76+
- uses: softprops/action-gh-release@v1
77+
if: startsWith(github.ref, 'refs/tags/')
78+
with:
79+
files: ./*-MyAlgorithm.zip
80+
env:
81+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
82+
83+
84+

.gitignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**/*-private
2+
/**/log.txt
3+
/**/*history
4+
5+
/build/
6+
/tmp/
7+
/nbproject/
8+
/dist/
9+
/test/
10+
11+
/*.png
12+
/*.html
13+
/*.log
14+
/*.zip
15+
/*.out
16+
/*.csv
17+
/*.txt
18+
/*.Rout
19+
/*.Rdata
20+
/*.Rmd
21+
/*.exec
22+
23+
/FunzR-*
24+
/libR/

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[![.github/workflows/ant.yml](https://github.com/Funz/algorithm-MyAlgorithm/actions/workflows/ant.yml/badge.svg)](https://github.com/Funz/algorithm-MyAlgorithm/actions/workflows/ant.yml)
2+
3+
___This repositry is intended to be forked as a basis for an new algorithm implementation.___
4+
___You can search for "MyAlgorithm" as a key to replace everywhere in this directory.___
5+
6+
# Funz algorithm: MyAlgorithm
7+
8+
* MyAlgorithm method for ...
9+
* author: ...
10+
* ref: ...
11+
* tags: ...
12+
* options: ...
13+
* input: ...
14+
* output: ...
15+
16+
17+
![Analytics](https://ga-beacon.appspot.com/UA-109580-20/algorithm-MyAlgorithm)

build.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<project name="algorithm-MyAlgorithm" default="test" basedir=".">
2+
3+
<property name="algorithm.name" value="MyAlgorithm" />
4+
<property name="install.dir" value="${basedir}/FunzR-${algorithm.name}" />
5+
6+
<property name="funz.release" value="v1.12" />
7+
8+
<property name="build_algorithm.xml" location="../funz-profile/build_algorithm.xml" />
9+
<import file="${build_algorithm.xml}"/>
10+
11+
<target name="dist" depends="dist-algorithm"/> <!-- dist-ioplugin: copy just the plugin ascii files -->
12+
13+
<target name="test" depends="test-algorithm"/> <!-- test-ioplugin: test the plugin ascii files -->
14+
15+
<target name="super.install" depends="install"/>
16+
<target name="super.clean" depends="clean"/>
17+
18+
</project>

src/main/doe/MyAlgorithm.R

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
#help: MyAlgorithm method for ...
2+
#author: ...
3+
#ref: ...
4+
#tags: ...
5+
#options: ytarget='0.0';ytol='3.e-8';xtol='1.e-8';xsample_size='10';max_iterations='10'
6+
#input: x=list(min=0,max=1)
7+
#output: y=0.01
8+
9+
MyAlgorithm <- function(options) {
10+
myAlgorithm = new.env()
11+
12+
myAlgorithm$ytol <- as.numeric(options$ytol)
13+
myAlgorithm$xtol <- as.numeric(options$xtol)
14+
myAlgorithm$ytarget <- as.numeric(options$ytarget)
15+
myAlgorithm$max_iterations <- as.integer(options$max_iterations)
16+
myAlgorithm$xsample_size <- as.integer(options$xsample_size)
17+
myAlgorithm$i = NA
18+
19+
return(myAlgorithm)
20+
}
21+
22+
#' first design building.
23+
#' @param input variables description (min/max, properties, ...)
24+
#' @param output values of interest description
25+
getInitialDesign <- function(myAlgorithm, input, output) {
26+
myAlgorithm$i <- 0
27+
myAlgorithm$input <- input
28+
x = matrix(runif(myAlgorithm$xsample_size * length(input)),ncol=length(input))
29+
names(x) <- names(input)
30+
return(from01(x,myAlgorithm$input))
31+
}
32+
33+
## iterated design building.
34+
## @param X data frame of current doe variables
35+
## @param Y data frame of current results
36+
## @return data frame or matrix of next doe step
37+
getNextDesign <- function(myAlgorithm, X, Y) {
38+
names(X) = names(myAlgorithm$input)
39+
X = to01(X,myAlgorithm$input)
40+
Y = matrix(Y,ncol=1) - myAlgorithm$ytarget
41+
42+
if (myAlgorithm$i >= myAlgorithm$max_iterations) {
43+
return(NULL)
44+
} else
45+
myAlgorithm$i = myAlgorithm$i+1
46+
47+
Xnext = matrix(runif(myAlgorithm$xsample_size * length(myAlgorithm$input)),ncol=length(myAlgorithm$input))
48+
names(Xnext) <- names(myAlgorithm$input)
49+
return(from01(Xnext,myAlgorithm$input))
50+
}
51+
52+
## final analysis. Return HTML string
53+
## @param X data frame of doe variables
54+
## @param Y data frame of results
55+
## @return HTML string of analysis
56+
displayResults <- function(myAlgorithm, X, Y) {
57+
myAlgorithm$files <- paste("result", myAlgorithm$i, ".png", sep = "")
58+
height <- 500
59+
width <- 500
60+
61+
png(file = myAlgorithm$files, height = height, width = width)
62+
pairs(cbind(X,Y))
63+
dev.off()
64+
65+
html <- paste0(' <HTML name="SomeInfo">Here is some information in the end','<br/>',
66+
'<img src="', myAlgorithm$files, '" width="', width, '" height="', height, '"/></HTML>',collapse=';')
67+
68+
info <- paste0('<info>',mean(Y),'</info>')
69+
70+
return(paste0(html,info))
71+
}
72+
73+
displayResultsTmp <- displayResults
74+
75+
from01 = function(X, inp) {
76+
for (i in 1:ncol(X)) {
77+
namei = names(X)[i]
78+
X[,i] = X[,i] * (inp[[ namei ]]$max-inp[[ namei ]]$min) + inp[[ namei ]]$min
79+
}
80+
return(X)
81+
}
82+
83+
to01 = function(X, inp) {
84+
for (i in 1:ncol(X)) {
85+
namei = names(X)[i]
86+
X[,i] = (X[,i] - inp[[ namei ]]$min) / (inp[[ namei ]]$max-inp[[ namei ]]$min)
87+
}
88+
return(X)
89+
}

src/test/cases/cos_pi.R

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
## This file should provide following objects, when loaded:
2+
# f : function
3+
# input.f : list of input dimensions, contains list of properties like lower & upper bounds of each dimensions
4+
# output.f : list of output dimensions
5+
# *.f : list of math properties. To be compared with algorithm results
6+
# [print.f] : method to print/plot the function for information
7+
8+
f = function(X) {
9+
matrix(Vectorize(function(x) {cos(pi*x)})(X),ncol=1)
10+
}
11+
input.f = list(
12+
x=list(min=0,max=1)
13+
)
14+
output.f = "cos_pi"
15+
root.f = 0.5
16+
17+
test = function(algorithm_file) {
18+
results = run.algorithm(algorithm_file, options=NULL,fun=list(input=input.f,output=output.f,fun=f))
19+
library(testthat)
20+
# Replace following test by something suitable
21+
#test_that("cos_pi info",{expect_equal(as.numeric(results$info),root.f,tolerance = .0001)})
22+
}
23+

src/test/cases/poly3.R

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
## This file should provide following objects, when loaded:
2+
# f : function
3+
# input.f : list of input dimensions, contains list of properties like lower & upper bounds of each dimensions
4+
# output.f : list of output dimensions
5+
# *.f : list of math properties. To be compared with algorithm results
6+
# [print.f] : method to print/plot the function for information
7+
8+
f = function(X) {
9+
matrix(Vectorize(function(x) {((x-.75)/3)^3})(X),ncol=1)
10+
}
11+
input.f = list(
12+
x=list(min=0,max=1)
13+
)
14+
output.f = "poly3"
15+
info.f = 0.75
16+
17+
test = function(algorithm_file) {
18+
results = run.algorithm(algorithm_file, options=NULL,fun=list(input=input.f,output=output.f,fun=f))
19+
library(testthat)
20+
# Replace following test by something suitable
21+
#test_that("poly3 info",{expect_equal(as.numeric(results$info),info.f,tolerance = .0001)})
22+
}
23+

0 commit comments

Comments
 (0)