From 5ba18cd1d8115f2fa385bc1aeffe4615c60d8f60 Mon Sep 17 00:00:00 2001 From: Joshua Moerman Date: Sun, 25 Mar 2012 23:23:13 +0200 Subject: [PATCH] added stub of analyser --- AwesomeAttract0r.xcodeproj/project.pbxproj | 119 +++++++++++++++++++++ Logger.hpp | 22 ++-- aatester.cpp | 72 +++++++++++++ analyse.hpp | 47 ++++++++ kernels/Polynomial.hpp | 2 +- main.cpp | 4 +- 6 files changed, 252 insertions(+), 14 deletions(-) create mode 100644 aatester.cpp create mode 100644 analyse.hpp diff --git a/AwesomeAttract0r.xcodeproj/project.pbxproj b/AwesomeAttract0r.xcodeproj/project.pbxproj index d3e5b0d..edeeaf1 100644 --- a/AwesomeAttract0r.xcodeproj/project.pbxproj +++ b/AwesomeAttract0r.xcodeproj/project.pbxproj @@ -15,10 +15,29 @@ 01C5704413B63BBE009D151B /* Normalizer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 01C5704213B63BBE009D151B /* Normalizer.cpp */; }; 01C5707E13B63CF9009D151B /* libpng.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 01C5707D13B63CF9009D151B /* libpng.a */; }; 4214149414A9D9B6004016D6 /* libboost_program_options.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 4214149314A9D9B6004016D6 /* libboost_program_options.dylib */; }; + 42CA52B9151F93940098800C /* libpng.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 01C5707D13B63CF9009D151B /* libpng.a */; }; + 42CA52BA151F93960098800C /* libboost_program_options.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 4214149314A9D9B6004016D6 /* libboost_program_options.dylib */; }; + 42CA52BB151F93A90098800C /* Projector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 01C5700713B63AF0009D151B /* Projector.cpp */; }; + 42CA52BC151F93AB0098800C /* Projection.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 01C5704013B63BBE009D151B /* Projection.cpp */; }; + 42CA52BD151F93AE0098800C /* Normalizer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 01C5704213B63BBE009D151B /* Normalizer.cpp */; }; + 42CA52BE151F93B30098800C /* AttractorKernel.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 01C5700F13B63AF0009D151B /* AttractorKernel.cpp */; }; + 42CA52BF151F93BA0098800C /* stf.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 01C5703113B63B78009D151B /* stf.cpp */; }; + 42CA52C0151F93CF0098800C /* Attractor.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 01C5701113B63AF0009D151B /* Attractor.cpp */; }; + 42CA52C2151F93E40098800C /* aatester.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 42CA52C1151F93E40098800C /* aatester.cpp */; }; + 42CA52C3151F93FC0098800C /* aatester.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 42CA52C1151F93E40098800C /* aatester.cpp */; }; 8DD76F650486A84900D96B5E /* main.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 08FB7796FE84155DC02AAC07 /* main.cpp */; settings = {ATTRIBUTES = (); }; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ + 42CA52AB151F93650098800C /* CopyFiles */ = { + isa = PBXCopyFilesBuildPhase; + buildActionMask = 2147483647; + dstPath = /usr/share/man/man1/; + dstSubfolderSpec = 0; + files = ( + ); + runOnlyForDeploymentPostprocessing = 1; + }; 8DD76F690486A84900D96B5E /* CopyFiles */ = { isa = PBXCopyFilesBuildPhase; buildActionMask = 8; @@ -68,12 +87,24 @@ 4299F17414B256F700EDE788 /* std_string_ext.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = std_string_ext.hpp; path = stfu/std_string_ext.hpp; sourceTree = ""; }; 4299F17814B2579B00EDE788 /* stf_input.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = stf_input.hpp; path = stfu/stf_input.hpp; sourceTree = ""; }; 4299F17914B2579B00EDE788 /* stf_output.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = stf_output.hpp; path = stfu/stf_output.hpp; sourceTree = ""; }; + 42CA52A7151F70F00098800C /* analyse.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = analyse.hpp; sourceTree = ""; }; + 42CA52AD151F93650098800C /* AATester */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = AATester; sourceTree = BUILT_PRODUCTS_DIR; }; + 42CA52C1151F93E40098800C /* aatester.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = aatester.cpp; sourceTree = ""; }; 42CEC38414AB797200C3AEDA /* Random.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = Random.hpp; sourceTree = ""; }; 42CEC38614ABB85200C3AEDA /* stf_ext.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = stf_ext.hpp; path = stfu/stf_ext.hpp; sourceTree = ""; }; 42CEC38714ABC2C000C3AEDA /* UnravelHeart3D.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = UnravelHeart3D.hpp; path = kernels/UnravelHeart3D.hpp; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ + 42CA52AA151F93650098800C /* Frameworks */ = { + isa = PBXFrameworksBuildPhase; + buildActionMask = 2147483647; + files = ( + 42CA52B9151F93940098800C /* libpng.a in Frameworks */, + 42CA52BA151F93960098800C /* libboost_program_options.dylib in Frameworks */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; 8DD76F660486A84900D96B5E /* Frameworks */ = { isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; @@ -146,7 +177,9 @@ 01C5701013B63AF0009D151B /* Attractor.hpp */, 01C5701113B63AF0009D151B /* Attractor.cpp */, 08FB7796FE84155DC02AAC07 /* main.cpp */, + 42CA52C1151F93E40098800C /* aatester.cpp */, 428981DF14BA1EB1000C437F /* render.hpp */, + 42CA52A7151F70F00098800C /* analyse.hpp */, 428981DD14BA1D72000C437F /* output.hpp */, ); name = Source; @@ -156,6 +189,7 @@ isa = PBXGroup; children = ( 01C5701613B63AF0009D151B /* AwesomeAttract0r */, + 42CA52AD151F93650098800C /* AATester */, ); name = Products; sourceTree = ""; @@ -192,6 +226,23 @@ /* End PBXGroup section */ /* Begin PBXNativeTarget section */ + 42CA52AC151F93650098800C /* AATester */ = { + isa = PBXNativeTarget; + buildConfigurationList = 42CA52B4151F93650098800C /* Build configuration list for PBXNativeTarget "AATester" */; + buildPhases = ( + 42CA52A9151F93650098800C /* Sources */, + 42CA52AA151F93650098800C /* Frameworks */, + 42CA52AB151F93650098800C /* CopyFiles */, + ); + buildRules = ( + ); + dependencies = ( + ); + name = AATester; + productName = AATester; + productReference = 42CA52AD151F93650098800C /* AATester */; + productType = "com.apple.product-type.tool"; + }; 8DD76F620486A84900D96B5E /* AwesomeAttract0r */ = { isa = PBXNativeTarget; buildConfigurationList = 1DEB923108733DC60010E9CD /* Build configuration list for PBXNativeTarget "AwesomeAttract0r" */; @@ -233,11 +284,26 @@ projectRoot = ""; targets = ( 8DD76F620486A84900D96B5E /* AwesomeAttract0r */, + 42CA52AC151F93650098800C /* AATester */, ); }; /* End PBXProject section */ /* Begin PBXSourcesBuildPhase section */ + 42CA52A9151F93650098800C /* Sources */ = { + isa = PBXSourcesBuildPhase; + buildActionMask = 2147483647; + files = ( + 42CA52C3151F93FC0098800C /* aatester.cpp in Sources */, + 42CA52BB151F93A90098800C /* Projector.cpp in Sources */, + 42CA52BC151F93AB0098800C /* Projection.cpp in Sources */, + 42CA52BD151F93AE0098800C /* Normalizer.cpp in Sources */, + 42CA52BE151F93B30098800C /* AttractorKernel.cpp in Sources */, + 42CA52BF151F93BA0098800C /* stf.cpp in Sources */, + 42CA52C0151F93CF0098800C /* Attractor.cpp in Sources */, + ); + runOnlyForDeploymentPostprocessing = 0; + }; 8DD76F640486A84900D96B5E /* Sources */ = { isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; @@ -249,6 +315,7 @@ 01C5703213B63B78009D151B /* stf.cpp in Sources */, 01C5704313B63BBE009D151B /* Projection.cpp in Sources */, 01C5704413B63BBE009D151B /* Normalizer.cpp in Sources */, + 42CA52C2151F93E40098800C /* aatester.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -330,6 +397,50 @@ }; name = Debug; }; + 42CA52B5151F93650098800C /* Debug */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ARCHS = "$(ARCHS_STANDARD_64_BIT)"; + COPY_PHASE_STRIP = NO; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_DYNAMIC_NO_PIC = NO; + GCC_ENABLE_OBJC_EXCEPTIONS = YES; + GCC_PREPROCESSOR_DEFINITIONS = ( + "DEBUG=1", + "$(inherited)", + ); + GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_VERSION = com.apple.compilers.llvm.clang.1_0; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.7; + PRODUCT_NAME = "$(TARGET_NAME)"; + }; + name = Debug; + }; + 42CA52B6151F93650098800C /* Release with Symbols */ = { + isa = XCBuildConfiguration; + buildSettings = { + ALWAYS_SEARCH_USER_PATHS = NO; + ARCHS = "$(ARCHS_STANDARD_64_BIT)"; + COPY_PHASE_STRIP = YES; + DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; + GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_ENABLE_OBJC_EXCEPTIONS = YES; + GCC_VERSION = com.apple.compilers.llvm.clang.1_0; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; + GCC_WARN_ABOUT_MISSING_PROTOTYPES = YES; + GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNUSED_VARIABLE = YES; + MACOSX_DEPLOYMENT_TARGET = 10.7; + PRODUCT_NAME = "$(TARGET_NAME)"; + SDKROOT = macosx; + }; + name = "Release with Symbols"; + }; /* End XCBuildConfiguration section */ /* Begin XCConfigurationList section */ @@ -351,6 +462,14 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Debug; }; + 42CA52B4151F93650098800C /* Build configuration list for PBXNativeTarget "AATester" */ = { + isa = XCConfigurationList; + buildConfigurations = ( + 42CA52B5151F93650098800C /* Debug */, + 42CA52B6151F93650098800C /* Release with Symbols */, + ); + defaultConfigurationIsVisible = 0; + }; /* End XCConfigurationList section */ }; rootObject = 08FB7793FE84155DC02AAC07 /* Project object */; diff --git a/Logger.hpp b/Logger.hpp index 2eacfae..63de543 100644 --- a/Logger.hpp +++ b/Logger.hpp @@ -10,24 +10,24 @@ extern int verbose; +enum LoggingLevels { + LOG_ERROR, + LOG_INFO, + LOG_VERBOSE, + LOG_DEBUG +}; + #define LogDebug(s, ...) \ - if ( verbose >= 3 ) printf(s, ##__VA_ARGS__); + if ( verbose >= LOG_DEBUG ) printf(s, ##__VA_ARGS__); #define LogMoreInfo(s, ...) \ - if ( verbose >= 2 ) printf(s, ##__VA_ARGS__); + if ( verbose >= LOG_VERBOSE ) printf(s, ##__VA_ARGS__); #define LogInfo(s, ...) \ - if ( verbose >= 1 ) printf(s, ##__VA_ARGS__); + if ( verbose >= LOG_INFO ) printf(s, ##__VA_ARGS__); #define LogError(s, ...) \ - if ( verbose >= 0 ) { printf("%s, %s(), %d: ", __FILE__, __func__, __LINE__); printf(s, ##__VA_ARGS__); } - -enum LoggingLevels { - LOG_ERROR, - LOG_INFO, - LOG_VERBOSE, - LOG_DEBUG -}; + if ( verbose >= LOG_ERROR ) { printf("%s, %s(), %d: ", __FILE__, __func__, __LINE__); printf(s, ##__VA_ARGS__); } /* Imported from Astrant: diff --git a/aatester.cpp b/aatester.cpp new file mode 100644 index 0000000..afba8b0 --- /dev/null +++ b/aatester.cpp @@ -0,0 +1,72 @@ +// +// aatester.cpp +// AwesomeAttract0r +// +// Created by Joshua Moerman on 3/25/12. +// Copyright (c) 2012 Vadovas. All rights reserved. +// + +#include +#include + +#include "Logger.hpp" +#include "analyse.hpp" + +#define LOG(s, p) \ + logger.start(s); \ + p \ + logger.stop() + +int verbose = 0; +Logger logger(std::cout, LOG_VERBOSE); + +inline double test(const int dimension, const double doubling, const double percentage){ + LOG("making vector", + srand(time(0)); + std::vector buffer(1000000); + ); + + LOG("making random data", + for(auto & p : buffer){ + p = new double[dimension]; + for(unsigned int i = 2;i < dimension; ++i){ + p[i] = rand() / (double) RAND_MAX - 0.5; + } + p[0] = p[1]*p[1]; + p[1] = std::sin(5.0*p[2]); + }); + + LOG("calculate fractal dimension", + double f = fractal_dimension(buffer.begin(), buffer.end(), dimension, doubling, percentage); + ); + + LOG("freeing data", + for(auto & p : buffer){ + delete[] p; + p = 0; + }); + + return f; +} + +int main(){ + double percentages[] = {0.00015, 0.00010, 0.00006, 0.00004, 0.000015}; + std::cout << "... |"; + for(auto p : percentages) std::cout << "\t" << p; + std::cout << std::endl << "----------------------------------------------" << std::endl; + + for (double doubling = 2.0; doubling <= 3.0; doubling += 0.1){ + std::cout << doubling << " |"; + for (auto p : percentages){ + double sse = 0; + for (int i = 3; i <= 6; ++i) { + for(int j = 0; j < 20; ++j) { + double e = (i-2) - test(i, doubling, p); + sse += e*e; + } + } + std::cout << "\t" << sse; + } + std::cout << std::endl; + } +} diff --git a/analyse.hpp b/analyse.hpp new file mode 100644 index 0000000..b56e8b3 --- /dev/null +++ b/analyse.hpp @@ -0,0 +1,47 @@ +// +// analyse.hpp +// AwesomeAttract0r +// +// Created by Joshua Moerman on 3/25/12. +// Copyright (c) 2012 Vadovas. All rights reserved. +// + +#ifndef AwesomeAttract0r_analyse_hpp +#define AwesomeAttract0r_analyse_hpp + +#include + +inline double distance_squared(double * p1, double * p2, size_t dimension){ + double s = 0; + for(unsigned int i = 0; i < dimension; ++i){ + s += (p1[i] - p2[i]) * (p1[i] - p2[i]); + } + return s; +} + +template +double fractal_dimension(Iterator begin, Iterator end, size_t const dimension, const double doubling = 2.4, const double percentage = 0.00004) { + const double size = std::pow(percentage, 1.0 / 3.0); + //const double size = std::pow(percentage, 1.0 / dimension); + const double totalSize = std::sqrt(dimension); + + unsigned int counts[2] = {}; + double r = size * totalSize; + + while(begin != end){ + auto x0 = *begin++; + + for(unsigned int i = 0; i < 200 && begin != end; ++i){ + auto x = *begin++; + auto d = distance_squared(x, x0, dimension); + if( d <= r*r ) + ++counts[0]; + if( d <= doubling*doubling*r*r ) + ++counts[1]; + } + } + + return std::log((double) counts[1] / (double) counts[0]) / std::log(doubling); +} + +#endif diff --git a/kernels/Polynomial.hpp b/kernels/Polynomial.hpp index 626fbda..8d57830 100644 --- a/kernels/Polynomial.hpp +++ b/kernels/Polynomial.hpp @@ -3,7 +3,7 @@ #include "../AttractorKernel.hpp" -unsigned int calculateNumberOfParameters(const unsigned int dimension, const unsigned int orde) { +inline unsigned int calculateNumberOfParameters(const unsigned int dimension, const unsigned int orde) { double n_coef = orde + 1; for(unsigned int i = 2; i <= dimension; i++) { n_coef = n_coef*(orde + i)/(i - 1); diff --git a/main.cpp b/main.cpp index f07499e..70dae79 100644 --- a/main.cpp +++ b/main.cpp @@ -17,7 +17,7 @@ namespace po = boost::program_options; #include "render.hpp" -int verbose = 4; +int verbose = LOG_DEBUG; Logger logger(std::cout, LOG_VERBOSE); std::string generate_filename(){ @@ -31,7 +31,7 @@ std::string generate_filename(){ void save_stf(stfu::node & stf_output, std::string const & filename){ stf_output.addValue("version") = __DATE__" "__TIME__; - stf_output.addValue("notes") = "This is the version with `cheap` blur and random colours"; + stf_output.addValue("notes") = "This is the version with somewhat better blur (circle) and random colours"; std::string path(filename + ".stf"); std::ofstream file(path.c_str()); file << stf_output << std::endl;