Skip to content

Commit

Permalink
further improvement EM algorithm implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Kohlbrecher committed May 8, 2019
1 parent c704d4b commit 1def2e3
Show file tree
Hide file tree
Showing 20 changed files with 2,794 additions and 308 deletions.
Binary file modified CHANGES.txt
Binary file not shown.
11 changes: 10 additions & 1 deletion sasfit.vfs/lib/app-sasfit/tcl/sasfit_OZ_solver.tcl
Expand Up @@ -612,6 +612,15 @@ proc oz_input_names {} {
set OZ(p5,name) K3
set OZ(p6,name) lambda3
}
"DLVO Hydra" {
set OZ(p0,name) diameter
set OZ(p1,name) kappa
set OZ(p2,name) Z
set OZ(p3,name) LB
set OZ(p4,name) A
set OZ(p5,name) gHy
set OZ(p6,name) DH
}
default {
set OZ(p0,name) ""
set OZ(p1,name) ""
Expand Down Expand Up @@ -892,7 +901,7 @@ proc sasfit_OZ_solver {} {
"StarPolymer (f>10)" "StarPolymer (f<10)" "HS 3Yukawa"\
"LennardJones" "Depl-Sph-Sph" "Depl-Sph-Discs" "Depl-Sph-Rods" \
"IonicMicrogel" \
"PenetrableSphere" "Fermi" "DLVO" "GGCM-n"} \
"PenetrableSphere" "Fermi" "DLVO" "DLVO Hydra" "GGCM-n"} \
-textvariable OZ(potential) \
-modifycmd {oz_input_names} -editable 0
grid $w.param.potvalue\
Expand Down
4 changes: 2 additions & 2 deletions sasfit.vfs/lib/app-sasfit/tcl/sasfit_main.tcl
Expand Up @@ -415,10 +415,10 @@ set FitPrecision(Robertus_p) 9
set FitPrecision(iter_4_MC) 1000
set FitPrecision(int) no

set EMOptions(IterationScheme) Picard
set EMOptions(IterationScheme) "Picard iteration"
set EMOptions(spacing) lin
set EMOptions(smooth) 1e-4
set EMOptions(smooth_type) single
set EMOptions(smooth_type) double
set EMOptions(seed) constant
set EMOptions(Rmax) 1000
set EMOptions(nR) 100
Expand Down
14 changes: 12 additions & 2 deletions sasfit.vfs/lib/app-sasfit/tcl/sasfit_structural.tcl
Expand Up @@ -106,7 +106,17 @@ proc EmOptionsCmd {} {
grid $w.maxitvalue -row 2 -column 3 -sticky w

label $w.intStrat_label -text "iteration scheme"
ComboBox $w.intStrat_value -values {"Picard" "Anderson" "GMRES"} \
ComboBox $w.intStrat_value -values {"Picard iteration" "Mann iteration" \
"Ishikawa iteration" "Noor iteration" \
"SP iteration" "S iteration" \
"CR iteration" "Picard-S iteration" \
"PMH iteration" "Mann II iteration" \
"Krasnoselskij iteration" \
"S* iteration" \
"dNewton" "Hybrid" \
"Hybrids (int. sc.)" "Broyden" \
"Anderson mixing" "KINSOL_FP" "GMRES" "Bi-CGStab" "TFQMR" "FGMRES"
} \
-width 10 \
-textvariable ::EMOptions(IterationScheme)
grid $w.intStrat_label -row 3 -column 0 -sticky e
Expand All @@ -132,7 +142,7 @@ proc EmOptionsCmd {} {
label $w.dimlabel -text "dim ="
entry $w.dimvalue -textvariable EMOptions(dim) -width $entrywidth
grid $w.dimlabel -row 5 -column 0 -sticky e
grid $w.dimvalue -row 6 -column 1 -sticky w
grid $w.dimvalue -row 5 -column 1 -sticky w

}
proc structuralParFitCmd {} {
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Expand Up @@ -214,7 +214,7 @@ add_definitions(
# get a list of all source files and prepare include dirs
set(SRC_FILES "")
set(SF_INC_DIRS "")
foreach(SF_MODULE f2c sasfit_common sasfit_sd sasfit_sq sasfit_ff sasfit_core sasfit_old sasfit_oz sasfit_frida)
foreach(SF_MODULE f2c sasfit_common sasfit_sd sasfit_sq sasfit_ff sasfit_core sasfit_old sasfit_oz sasfit_fixed_point_acc sasfit_frida)
if(IS_DIRECTORY ${CURRENT_DIR}/${SF_MODULE})
foreach(SRC_FILE ${SOURCE_${SF_MODULE}})
list(APPEND SRC_FILES "${SF_MODULE}/${SRC_FILE}")
Expand Down
70 changes: 70 additions & 0 deletions src/cmake/Findsasfit_fixed_point_acc.cmake
@@ -0,0 +1,70 @@
# src/cmake/Findsasfit_fixed_point_acc.cmake
#
# Copyright (c) 2008-2019, Paul Scherrer Institute (PSI)
#
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the <organization> nor the
# names of its contributors may be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
# Author(s) of this file:
# Joachim Kohlbrecher (joachim.kohlbrecher@psi.ch)

# Find the sasfit_fixed_point_acc includes and library
#
# sasfit_fixed_point_acc_INCLUDE_DIRS - where to find the touch lib header files
# sasfit_fixed_point_acc_LIBRARIES - List of fully qualified libraries to link
# against.
# sasfit_fixed_point_acc_FOUND - Do not attempt to use if "no" or undefined.

GET_FILENAME_COMPONENT(CURRENT_DIR ${CMAKE_CURRENT_LIST_FILE} PATH)
GET_FILENAME_COMPONENT(CURRENT_DIR "${CURRENT_DIR}/.." ABSOLUTE)

FIND_PATH(sasfit_fixed_point_acc_INCLUDE_DIR sasfit_fixed_point_acc.h
${CURRENT_DIR}/sasfit_fixed_point_acc/include/
)

FIND_LIBRARY(sasfit_fixed_point_LIBRARY sasfit_fixed_point_acc
${CURRENT_DIR}/sasfit_fixed_point_acc/lib/
${CURRENT_DIR}/sasfit_fixed_point_acc/lib/debug/
${CURRENT_DIR}/sasfit_fixed_point_acc/lib/release/
)

IF(sasfit_ff_INCLUDE_DIR)
SET(sasfit_fixed_point_acc_FOUND "YES")
SET(sasfit_fixed_point_acc_INCLUDE_DIRS ${sasfit_fixed_point_acc_INCLUDE_DIR})
IF(sasfit_fixed_point_acc_LIBRARY)
SET(sasfit_fixed_point_acc_LIBRARIES ${sasfit_fixed_point_acc_LIBRARY})
ELSE(sasfit_fixed_point_acc_LIBRARY)
MESSAGE(STATUS "sasfit_fixed_point_acc library not found!")
ENDIF(sasfit_fixed_point_acc_LIBRARY)
ELSE(sasfit_fixed_point_acc_INCLUDE_DIR)
MESSAGE(STATUS "sasfit_fixed_point_acc include dir not found!")
ENDIF(sasfit_fixed_point_acc_INCLUDE_DIR)

MESSAGE(STATUS "found sasfit_fixed_point_acc inc: ${sasfit_fixed_point_acc_INCLUDE_DIR}")
MESSAGE(STATUS "found sasfit_fixed_point_acc lib: ${sasfit_fixed_point_acc_LIBRARY}")

IF(NOT sasfit_fixed_point_acc_FOUND)
MESSAGE(SEND_ERROR "The sasfit_fixed_point_acc library was not found. For adjustments use ${CMAKE_CURRENT_LIST_FILE}.")
ENDIF(NOT sasfit_fixed_point_acc_FOUND)

8 changes: 4 additions & 4 deletions src/cmake/Findsasfit_frida.cmake
Expand Up @@ -39,17 +39,17 @@
GET_FILENAME_COMPONENT(CURRENT_DIR ${CMAKE_CURRENT_LIST_FILE} PATH)
GET_FILENAME_COMPONENT(CURRENT_DIR "${CURRENT_DIR}/.." ABSOLUTE)

FIND_PATH(sasfit_oz_INCLUDE_DIR sasfit_frida.h
${CURRENT_DIR}/sasfit_ff/include/
FIND_PATH(sasfit_frida_INCLUDE_DIR sasfit_frida.h
${CURRENT_DIR}/sasfit_frida/include/
)

FIND_LIBRARY(sasfit_ff_LIBRARY sasfit_frida
FIND_LIBRARY(sasfit_frida_LIBRARY sasfit_frida
${CURRENT_DIR}/sasfit_frida/lib/
${CURRENT_DIR}/sasfit_frida/lib/debug/
${CURRENT_DIR}/sasfit_frida/lib/release/
)

IF(sasfit_ff_INCLUDE_DIR)
IF(sasfit_frida_INCLUDE_DIR)
SET(sasfit_frida_FOUND "YES")
SET(sasfit_frida_INCLUDE_DIRS ${sasfit_frida_INCLUDE_DIR})
IF(sasfit_frida_LIBRARY)
Expand Down
4 changes: 2 additions & 2 deletions src/cmake/Findsasfit_oz.cmake
Expand Up @@ -40,10 +40,10 @@ GET_FILENAME_COMPONENT(CURRENT_DIR ${CMAKE_CURRENT_LIST_FILE} PATH)
GET_FILENAME_COMPONENT(CURRENT_DIR "${CURRENT_DIR}/.." ABSOLUTE)

FIND_PATH(sasfit_oz_INCLUDE_DIR sasfit_oz.h
${CURRENT_DIR}/sasfit_ff/include/
${CURRENT_DIR}/sasfit_oz/include/
)

FIND_LIBRARY(sasfit_ff_LIBRARY sasfit_oz
FIND_LIBRARY(sasfit_oz_LIBRARY sasfit_oz
${CURRENT_DIR}/sasfit_oz/lib/
${CURRENT_DIR}/sasfit_oz/lib/debug/
${CURRENT_DIR}/sasfit_oz/lib/release/
Expand Down
5 changes: 5 additions & 0 deletions src/cmake/SasfitSourceFiles.cmake
Expand Up @@ -259,13 +259,18 @@ set(SOURCE_sasfit_oz
sasfit_oz_potential_psm.c
sasfit_oz_potential_ggcm-n.c
sasfit_oz_potential_dlvo.c
sasfit_oz_potential_dlvo_hydra.c
sasfit_oz_potential_star_Likos.c
sasfit_oz_potential_HS_3Yukawa.c
sasfit_oz_potential_FermiDistributionModel.c
sasfit_oz_potential_square_well.c
sasfit_oz_tclcmd.c
)

set(SOURCE_sasfit_fixed_point_acc
sasfit_fixed_point_acc.c
)

set(SOURCE_sasfit_frida
sasfit_frida_solver.c
)
Expand Down
4 changes: 4 additions & 0 deletions src/cmake/create_source_package.list
Expand Up @@ -687,6 +687,7 @@ src/sasfit_old/include/SASFIT_resolution.h
src/sasfit_oz/CMakeLists.txt
src/sasfit_oz/sasfit_oz_potential_depletion.c
src/sasfit_oz/sasfit_oz_potential_dlvo.c
src/sasfit_oz/sasfit_oz_potential_dlvo_hydra.c
src/sasfit_oz/sasfit_oz_potential_ggcm-n.c
src/sasfit_oz/sasfit_oz_potential_hard_sphere.c
src/sasfit_oz/sasfit_oz_potential_ionic_microgel.c
Expand All @@ -704,6 +705,9 @@ src/sasfit_oz/include/sasfit_oz.h
src/sasfit_oz/include/sasfit_oz_potentials.h
src/sasfit_oz/include/sasfit_oz_shared_exports.h
src/sasfit_oz/include/sasfit_oz_tclcmd.h
src/sasfit_fixed_point_acc/CMakeLists.txt
src/sasfit_fixed_point_acc/sasfit_fixed_point_acc.c
src/sasfit_fixed_point_acc/include/sasfit_fixed_point_acc.h
src/scripts/genStubs.tcl
src/scripts/clean_cmake.sh
src/scripts/addCopyrightNotice.sh
Expand Down
40 changes: 40 additions & 0 deletions src/sasfit_fixed_point_acc/CMakeLists.txt
@@ -0,0 +1,40 @@
cmake_minimum_required(VERSION 2.6.2)

# the project name
set(PRJ_NAME sasfit_fixed_point_acc)

# required external libs which are installed on the system
set(LIBS_EXT
GSL
FFTW
)

# required internal (sasfit_) libs
set(LIBS_INT
f2c
sasfit_common
sasfit_sd
sasfit_sq
sasfit_ff
)

# for source file listings, see SasfitSourceFiles.cmake

# path to 'Find*.cmake' files in sasfit package,
# relative to the location of this file
set(REL_CMAKE_MODULE_PATH ../cmake)

set(LIB_IS_PLUGIN false)

# #
### not adjustments required below this line (usually) ###
# #

project(${PRJ_NAME})

set(SRC_DIR ${${PRJ_NAME}_SOURCE_DIR})
set(CMAKE_MODULE_PATH ${SRC_DIR}/${REL_CMAKE_MODULE_PATH})

include(SasfitCmakeUtils)
sasfit_cmake_library()

74 changes: 74 additions & 0 deletions src/sasfit_fixed_point_acc/include/sasfit_fixed_point_acc.h
@@ -0,0 +1,74 @@
/*
* Author(s) of this file:
* Joachim Kohlbrecher (joachim.kohlbrecher@psi.ch)
*/

#ifndef SASFIT_FP
#define SASFIT_FP

#include <tcl.h>
#include <sasfit_common.h>

#include <stdio.h>
#include <gsl/gsl_errno.h>
#include <gsl/gsl_math.h>
#include <gsl/gsl_vector.h>
#include <gsl/gsl_roots.h>
#include <gsl/gsl_sf.h>
#include <gsl/gsl_const_mksa.h>
#include <gsl/gsl_spline.h>

#include <nvector/nvector_serial.h>
#include "sasfit_oz.h"

typedef double FP_Operator (void *);

typedef struct {
Tcl_Interp *interp;
double *Ih, *DIh, *Ith, *h;
int indx_min_appearent_sigma, indx_max_appearent_sigma;
gsl_vector *DR;
double dr, dq;
int it;
int Npoints;
double mixcoeff;
int maxsteps;
double relerror;
double alpha;
double gNorm;
double KLD, JSD;
double Chi2Norm;
sasfit_oz_root_algorithms root_algorithm;
sasfit_oz_mixstrategy mixstrategy;
double *in, *out;
int interrupt;
int failed;
int PrintProgress;
Tcl_Obj *fp_obj;
int KINSetMAA;
void *kin_mem;
double KINSetFuncNormTol;
double KINSetScaledSteptol;
int KINSetNumMaxIters;
int KINSetPrintLevel;
int KINSetEtaForm;
double KINSetEtaConstValue;
int KINSpilsSetMaxRestarts;
int KINSolStrategy;
double KINSetMaxNewtonStep;
void *FPstructure;
N_Vector KINConstraints;
FP_Operator * FP_Op;

} sasfit_fp_data;

int FP_init (sasfit_fp_data *);
int FP_solver (sasfit_fp_data *);
int FP_free (sasfit_fp_data *);
static int FP_step_kinsol(N_Vector, N_Vector, void *);
static int FP_step_kinsolFP(N_Vector, N_Vector, void *);
double FP_step(sasfit_fp_data *);
int FP_solver_by_iteration(sasfit_fp_data *, sasfit_oz_root_algorithms );
//Modified 29.4.2019

#endif // SASFIT_FP

0 comments on commit 1def2e3

Please sign in to comment.