├── Adam ├── README.md └── sources │ ├── MAE.m │ ├── MakePredictionC.m │ ├── MemBasedCF.m │ ├── PearsonCorrelation.m │ ├── adamFusion.m │ ├── findKNNDirect.m │ ├── main.m │ ├── pccVectorActUser.m │ ├── pccVectors.m │ └── ssiUpdateSimMatrixActiveUser.m ├── CTR ├── CTR-manual.pdf ├── README.md └── code │ ├── addItemSupp.m │ ├── calConfidence.m │ ├── calDemoSupp.m │ ├── calInts1.m │ ├── calIntsConfL.m │ ├── calIntsConfN.m │ ├── calSupp.m │ ├── calSuppOne.m │ ├── calXSupp.m │ ├── findDecomposition.m │ ├── findSuprisingDeviation.m │ ├── genItem.m │ ├── genItemCand.m │ ├── genItemCandOne.m │ ├── genL.m │ ├── genTestL.m │ ├── generateGroup.m │ ├── generateLIST.m │ ├── generatePONElist.m │ ├── generatePONEset.m │ ├── generatePoList.m │ ├── generatefinalPONElist.m │ ├── getAttList.m │ ├── getAttValue.m │ ├── getCand.m │ ├── getCond.m │ ├── getItemSet.m │ ├── getRule.m │ ├── isSurprising.m │ ├── poNeContrast.m │ ├── sample.xlsx │ ├── savetofile.m │ ├── savetofile2.m │ ├── selectItem.m │ ├── selectItemOne.m │ └── writeXitem.m ├── DLM ├── DLM.py ├── Eval.py ├── Preprocess.py ├── README.md ├── Setting.py └── preprocess │ ├── reframed.pk │ └── scaler.pk ├── GANBLR ├── GANBLR.ipynb ├── GANBLR_Extend.ipynb ├── README.md └── data │ ├── discretized │ └── discretized_adult.csv │ └── original │ ├── adult.data │ └── adult.names ├── GP-DLM ├── DLM.py ├── Dynamic_time_warping_distance.py ├── README.md ├── configuration.py ├── forecasting.py └── pooling.py ├── IK-AHC ├── .gitignore ├── LICENSE ├── README.md ├── eva │ ├── eva_khc.m │ └── utils │ │ ├── format_result_table.py │ │ └── plot_parameter.py ├── exp_out │ └── khc │ │ └── ik │ │ └── .gitkeep ├── setup.m └── src │ ├── kernel │ └── IsolationKernel.m │ ├── metric │ ├── DenPurity.m │ ├── ExpDenPurity.m │ ├── Fmeasure.m │ ├── f1_tree.m │ └── hungarian.m │ └── models │ └── TAHC │ └── tahc_cluster.m ├── LICENSE ├── PREDICTIVITY ├── README.md ├── predictivity_length_granularity.py └── predictivity_ssa.py ├── README.md ├── RFM ├── README.md ├── Rfmtool.tar.gz ├── Rfmtool.zip ├── packages │ ├── DESCRIPTION │ ├── INDEX │ ├── MD5 │ ├── Meta │ │ ├── Rd.rds │ │ ├── data.rds │ │ ├── hsearch.rds │ │ ├── links.rds │ │ ├── nsInfo.rds │ │ └── package.rds │ ├── NAMESPACE │ ├── R │ │ ├── Rfmtool │ │ ├── Rfmtool.rdb │ │ └── Rfmtool.rdx │ ├── data │ │ ├── Original │ │ │ └── Singapore-Hotel2011.csv │ │ └── Preprocessed │ │ │ ├── Business-Asia.txt │ │ │ ├── Business-Europe.txt │ │ │ ├── Business-NothAmerica.txt │ │ │ ├── Business-Oceania.txt │ │ │ ├── Business.txt │ │ │ ├── Couple-Asia.txt │ │ │ ├── Couple-Europe.txt │ │ │ ├── Couple-NothAmerica.txt │ │ │ ├── Couple-Oceania.txt │ │ │ ├── Couple.txt │ │ │ ├── Family-America.txt │ │ │ ├── Family-Asia.txt │ │ │ ├── Family-Europe.txt │ │ │ ├── Family-Oceania.txt │ │ │ └── Family.txt │ ├── example │ │ ├── AMEvaluation.r │ │ ├── ChoquetEvaluation.r │ │ ├── DataAnalysisRoutine.r │ │ ├── PreferenceAnalysisExample.r │ │ ├── WAMEvaluation.r │ │ └── data.txt │ ├── help │ │ ├── AnIndex │ │ ├── Rfmtool.rdb │ │ ├── Rfmtool.rdx │ │ ├── aliases.rds │ │ └── paths.rds │ ├── html │ │ ├── 00Index.html │ │ └── R.css │ └── libs │ │ ├── i386 │ │ └── Rfmtool.dll │ │ └── x64 │ │ └── Rfmtool.dll └── sources │ ├── DESCRIPTION │ ├── NAMESPACE │ ├── R │ └── Rfmtool.r │ ├── inst │ ├── data │ │ ├── Original │ │ │ └── Singapore-Hotel2011.csv │ │ └── Preprocessed │ │ │ ├── Business-Asia.txt │ │ │ ├── Business-Europe.txt │ │ │ ├── Business-NothAmerica.txt │ │ │ ├── Business-Oceania.txt │ │ │ ├── Business.txt │ │ │ ├── Couple-Asia.txt │ │ │ ├── Couple-Europe.txt │ │ │ ├── Couple-NothAmerica.txt │ │ │ ├── Couple-Oceania.txt │ │ │ ├── Couple.txt │ │ │ ├── Family-America.txt │ │ │ ├── Family-Asia.txt │ │ │ ├── Family-Europe.txt │ │ │ ├── Family-Oceania.txt │ │ │ └── Family.txt │ └── example │ │ ├── AMEvaluation.r │ │ ├── ChoquetEvaluation.r │ │ ├── DataAnalysisRoutine.r │ │ ├── PreferenceAnalysisExample.r │ │ ├── WAMEvaluation.r │ │ └── data.txt │ ├── man │ ├── Rfmtool.Rd │ ├── fm.Choquet.Rd │ ├── fm.ChoquetMob.Rd │ ├── fm.Interaction.Rd │ ├── fm.Mobius.Rd │ ├── fm.Rd │ ├── fm.Shapley.Rd │ ├── fm.Zeta.Rd │ ├── fm.fitting.Rd │ └── fm.test.Rd │ └── src │ ├── Makevars │ ├── Makevars.win │ ├── colamd.c │ ├── colamd.h │ ├── commonlib.c │ ├── commonlib.h │ ├── declare.h │ ├── fortify.h │ ├── fuzzymeasurefit.cpp │ ├── fuzzymeasurefit.h │ ├── fuzzymeasuretools.cpp │ ├── fuzzymeasuretools.h │ ├── hbio.c │ ├── hbio.h │ ├── ini.c │ ├── ini.h │ ├── isfixedvar.c │ ├── lp_BFP.h │ ├── lp_BFP1.h │ ├── lp_BFP2.h │ ├── lp_Hash.c │ ├── lp_Hash.h │ ├── lp_LUSOL.c │ ├── lp_LUSOL.h │ ├── lp_MDO.c │ ├── lp_MDO.h │ ├── lp_MPS.c │ ├── lp_MPS.h │ ├── lp_SOS.c │ ├── lp_SOS.h │ ├── lp_crash.c │ ├── lp_crash.h │ ├── lp_explicit.h │ ├── lp_fortify.h │ ├── lp_lib.c │ ├── lp_lib.h │ ├── lp_matrix.c │ ├── lp_matrix.h │ ├── lp_mipbb.c │ ├── lp_mipbb.h │ ├── lp_params.c │ ├── lp_presolve.c │ ├── lp_presolve.h │ ├── lp_price.c │ ├── lp_price.h │ ├── lp_pricePSE.c │ ├── lp_pricePSE.h │ ├── lp_report.c │ ├── lp_report.h │ ├── lp_rlp.c │ ├── lp_rlp.h │ ├── lp_scale.c │ ├── lp_scale.h │ ├── lp_simplex.c │ ├── lp_simplex.h │ ├── lp_types.h │ ├── lp_utils.c │ ├── lp_utils.h │ ├── lp_wlp.c │ ├── lp_wlp.h │ ├── lpkit.h │ ├── lpslink56.c │ ├── lpsolve.h │ ├── lusol.c │ ├── lusol.h │ ├── lusol1.h │ ├── lusol2.h │ ├── lusol6a.h │ ├── lusol6l0.h │ ├── lusol6u.h │ ├── lusol7a.h │ ├── lusol8a.h │ ├── lusolio.c │ ├── lusolio.h │ ├── mmio.c │ ├── mmio.h │ ├── myblas.c │ ├── myblas.h │ ├── sparselib.c │ ├── sparselib.h │ ├── ufortify.h │ ├── wrapper.cpp │ ├── yacc_read.c │ └── yacc_read.h ├── RPLC └── readme.txt ├── STL-DADLM ├── DADLM.py ├── Eval.py ├── README.md ├── STLPreprocess.py └── Setting.py └── StreaKHC ├── .gitattributes ├── .gitignore ├── README.md ├── StreaKHC.py ├── bin ├── run_grid_evaluation.sh ├── setup.sh └── util │ ├── collect_and_format_results.sh │ ├── format_result_table.py │ ├── process_covtype.py │ └── shuffle_dataset.sh ├── data ├── raw │ ├── .gitkeep │ └── wine.csv └── runned │ ├── .gitkeep │ ├── ALLAML.csv │ ├── Isolet.csv │ ├── LSVT.csv │ ├── LandCover.csv │ ├── Segment.csv │ ├── Synthetic.csv │ ├── WDBC.csv │ ├── banknote.csv │ ├── glass.tsv │ ├── hill.csv │ ├── lung.csv │ ├── musk.csv │ ├── pendig.csv │ ├── seeds.csv │ └── spam.csv └── src ├── IKMapper.py ├── INode.py ├── __init__.py └── utils ├── Graphviz.py ├── __init__.py ├── deltasep_utils.py ├── dendrogram_purity.py ├── dendrogram_purity_pool.py ├── file_utils.py ├── logger.py └── serialize_trees.py /Adam/README.md: -------------------------------------------------------------------------------- 1 | # Adam 2 | --- 3 | 4 | | Field | Value | 5 | | --- | --- | 6 | | Title | Adam | 7 | | Type | Source Code | 8 | | Language | Matlab | 9 | | License | | 10 | | Status | Research Code | 11 | | Update Frequency | NO | 12 | | Date Published | 2013-01-31 | 13 | | Date Updated | 2019-01-31 | 14 | | Portal | https://github.com/tulip-lab/open-code | 15 | | URL | https://github.com/tulip-lab/open-code/tree/master/Adam| 16 | | Publisher |[TULIP Lab](http://www.tulip.org.au/) | 17 | | Point of Contact |[A/Prof. Gang Li](https://github.com/tuliplab) | 18 | 19 | This package (Adam) implemented the algorithm to impute the missing data set for collaborative filtering. 20 | 21 | --- 22 | ## Citations 23 | --- 24 | 25 | If you use it for a scientific publication, please include a reference to this paper. 26 | 27 | * Yongli Ren, Gang Li, Jun Zhang, Wanlei Zhou. [Lazy Collaborative Filtering for Datasets with Missing Values](http://dx.doi.org/10.1109/TSMCB.2012.2231411). **IEEE Transactions on Systems, Man, and Cybernetics, Part B: Cybernetics**, 2013, 43(6): 1822-1834. 28 | 29 | * Yongli Ren, Gang Li, Jun Zhang and Wanlei Zhou. [AdaM: adaptive-maximum imputation for neighborhood-based collaborative filtering](http://dx.doi.org/10.1145/2492517.2492565). **2013 IEEE/ACM International Conference on Advances in Social Networks Analysis and Mining (ASONAM 2013)**, Aug 25-28, 2013 in Niagara Falls, Canada. Full Paper. 30 | 31 | `BibTex` information: 32 | 33 | @Article{RLZZ13J09, 34 | author = {Ren, Yongli and Li, Gang and Zhang, Jun and Zhou, Wanlei}, 35 | title = {Lazy Collaborative Filtering for Datasets with Missing Values}, 36 | journal = {IEEE Transactions on Systems, Man, and Cybernetics, Part B: Cybernetics}, 37 | year = {2013}, 38 | volume = {43}, 39 | number = {6}, 40 | pages = {1822-1834}, 41 | owner = {Quan}, 42 | timestamp = {2014.01.06}, 43 | } 44 | 45 | @InProceedings{RLZZ13C02, 46 | author = {Ren, Yongli and Li, Gang and Zhang, Jun and Zhou, Wanlei}, 47 | title = {AdaM: Adaptive-Maximum Imputation for Neighborhood-based Collaborative Filtering}, 48 | booktitle = {ASONAM 2013 : Proceedings of the IEEE/ACM International Conference on Advances in Social Networks Analysis and Mining}, 49 | year = {2013}, 50 | pages = {628-635}, 51 | address = {Niagara Falls, Canada}, 52 | owner = {Quan}, 53 | timestamp = {2014.01.06}, 54 | } 55 | 56 | --- 57 | ## Requirements 58 | --- 59 | 60 | * Matlab 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /Adam/sources/MAE.m: -------------------------------------------------------------------------------- 1 | function [value] = MAE(ratings, predictions) 2 | 3 | value = sum(abs(ratings - predictions))/length(ratings); 4 | 5 | return 6 | end -------------------------------------------------------------------------------- /Adam/sources/MakePredictionC.m: -------------------------------------------------------------------------------- 1 | function [prediction] = MakePredictionC(ActiveVector, neighborhood, TestData, neigh_w, i, maxValue, minValue) 2 | 3 | if length(find(neigh_w)) == 0 4 | if length(find(ActiveVector)) == 0 5 | prediction = 0; 6 | else 7 | prediction = sum(ActiveVector)/length(find(ActiveVector)); 8 | end 9 | else 10 | 11 | MissItem = TestData(i,2); 12 | 13 | Mean_ActiveUser = sum(ActiveVector)/length(find(ActiveVector)); 14 | 15 | denominator = sum(abs(neigh_w)); 16 | 17 | [n m] = size(neighborhood); 18 | if m < MissItem 19 | NeighMissItem = neighborhood(:, end); 20 | neighborhood(:,end) = 0; 21 | else 22 | NeighMissItem = neighborhood(:, MissItem); 23 | neighborhood(:,MissItem) = 0; 24 | end 25 | 26 | 27 | 28 | MeanNeighbor = zeros(1, n); 29 | for k = 1:n 30 | SingleNeigh = neighborhood(k,:); 31 | LenInds = length(find(SingleNeigh)); 32 | if LenInds~=0 33 | MeanNeighbor(k) = sum(SingleNeigh)/LenInds; 34 | end 35 | end 36 | 37 | numerator = sum((neigh_w .* (NeighMissItem' - MeanNeighbor))); 38 | 39 | prediction = Mean_ActiveUser + numerator/denominator; 40 | 41 | if prediction > maxValue 42 | prediction = maxValue; 43 | end 44 | if prediction < minValue 45 | prediction = minValue; 46 | end 47 | 48 | end 49 | 50 | return -------------------------------------------------------------------------------- /Adam/sources/MemBasedCF.m: -------------------------------------------------------------------------------- 1 | function [prediction]=MemBasedCF(M, TestData, W, k, maxValue, minValue) 2 | 3 | [user_num item_num] = size(M); 4 | 5 | T_inds = ones(1, user_num); 6 | 7 | [user_num temp] = size(TestData); 8 | prediction = zeros(1, user_num); 9 | 10 | for i = 1: user_num 11 | 12 | ActiveVector = M(TestData(i,1),:); 13 | 14 | MisItem = TestData(i,2); 15 | Active_user = TestData(i,1); 16 | 17 | neigh_inds = find(T_inds .* M(:, MisItem)'); 18 | 19 | LenNeighInds = length(neigh_inds); 20 | 21 | if LenNeighInds == 0 22 | neigh_w = 0; 23 | neighborhood = []; 24 | elseif LenNeighInds < k 25 | neighborhood = M(neigh_inds, :); 26 | neigh_w = W(Active_user, neigh_inds); 27 | else 28 | 29 | All_neigh_w = W(Active_user, neigh_inds); 30 | [Sort_all_neigh_w Sort_all_neigh_inds] = sort(All_neigh_w, 'descend'); 31 | neighborhood = M(neigh_inds(Sort_all_neigh_inds(1:k)), :); 32 | neigh_w = Sort_all_neigh_w(1:k); 33 | end 34 | 35 | prediction(i) = MakePredictionC(ActiveVector, neighborhood, TestData, neigh_w, i, maxValue, minValue); 36 | end 37 | 38 | return -------------------------------------------------------------------------------- /Adam/sources/PearsonCorrelation.m: -------------------------------------------------------------------------------- 1 | function [W] = PearsonCorrelation(M) 2 | 3 | [m n] = size (M); 4 | W = zeros(m); 5 | 6 | for i = 1:m-1 7 | if mod(i, 100)== 0 fprintf('%d finished \n', i); end 8 | for j = i+1:m 9 | inds = find(M(i,:).*M(j,:)); 10 | if isempty(inds) 11 | W(i,j) = 0; 12 | W(j,i) = 0; 13 | else 14 | userIVector = M(i, :); 15 | userJVector = M(j, :); 16 | 17 | sim = pccVectors(userIVector(inds), userJVector(inds)); 18 | W(i,j) = sim; 19 | W(j,i) = W(i,j); 20 | end 21 | end 22 | end 23 | 24 | end -------------------------------------------------------------------------------- /Adam/sources/adamFusion.m: -------------------------------------------------------------------------------- 1 | function [predictionAll] = adamFusion(M, W, itemW, testSet, para) 2 | 3 | k = para.neighK; 4 | maxValue = para.maxValue; 5 | minValue = para.minValue; 6 | 7 | fprintf('Adam-Fusion Imputation Function \n'); 8 | 9 | testUserNum = size(testSet, 1); 10 | 11 | predictionFinal = []; 12 | predictionFinalICF = []; 13 | 14 | for testUserInd = 1:testUserNum 15 | 16 | if mod(testUserInd, 200) == 0 17 | fprintf([int2str(testUserInd) ' predicted. \n']); 18 | end 19 | 20 | testUser = testSet(testUserInd, 1); 21 | testItem = testSet(testUserInd, 2); 22 | 23 | impM = M; 24 | impMICF = M; 25 | 26 | [userKNN itemKNN] = findKNNDirect(M, testUser, testItem); 27 | [itemKNNICF userKNNICF] = findKNNDirect(M', testItem, testUser); 28 | 29 | impArea = M(userKNN, itemKNN); 30 | impAreaFull = para.fullM(userKNN, itemKNN); 31 | 32 | impAreaInd = find(impArea == 0); 33 | impArea(impAreaInd) = impAreaFull(impAreaInd); 34 | 35 | impM(userKNN, itemKNN) = impArea; 36 | 37 | impArea = M(userKNNICF, itemKNNICF); 38 | impAreaFull = para.fullM(userKNNICF, itemKNNICF); 39 | 40 | impAreaInd = find(impArea == 0); 41 | impArea(impAreaInd) = impAreaFull(impAreaInd); 42 | 43 | impMICF(userKNNICF, itemKNNICF) = impArea; 44 | 45 | impM(testUser, testItem) = 0; 46 | impMICF(testItem, testUser) = 0; 47 | 48 | %%% Update the impW 49 | [impW] = ssiUpdateSimMatrixActiveUser(impM, W, userKNN, testUser, para); 50 | 51 | [impWICF] = ssiUpdateSimMatrixActiveUser(impMICF', itemW, itemKNNICF, testItem, para); 52 | 53 | curUserPreRecord = []; 54 | curUserPreRecordICF = []; 55 | for neighInd = 1:k 56 | [curPrediction] = MemBasedCF(impM, [testUser testItem], impW, neighInd, maxValue, minValue); 57 | [curPredictionICF] = MemBasedCF(impMICF', [testItem testUser], impWICF, neighInd, maxValue, minValue); 58 | 59 | curUserPreRecord = [curUserPreRecord; curPrediction]; 60 | curUserPreRecordICF = [curUserPreRecordICF; curPredictionICF]; 61 | end 62 | 63 | predictionFinal = [predictionFinal curUserPreRecord]; 64 | predictionFinalICF = [predictionFinalICF curUserPreRecordICF]; 65 | end 66 | 67 | predictionAll.userBased = predictionFinal; 68 | predictionAll.itemBased = predictionFinalICF; 69 | 70 | return -------------------------------------------------------------------------------- /Adam/sources/findKNNDirect.m: -------------------------------------------------------------------------------- 1 | function [userKNN itemKNN] = findKNNDirect(M, testUser, testItem) 2 | 3 | userKNN = find(M(:, testItem)'); 4 | 5 | selNeiHood = M([testUser userKNN], :); 6 | selNeiHoodInd = find(selNeiHood); 7 | selNeiHood(selNeiHoodInd) = 1; 8 | 9 | numEachItem = sum(selNeiHood, 1); 10 | 11 | itemKNN = find(numEachItem); 12 | 13 | userKNN = [userKNN testUser]; 14 | itemKNN = itemKNN; 15 | 16 | return -------------------------------------------------------------------------------- /Adam/sources/main.m: -------------------------------------------------------------------------------- 1 | function main(M, TestData, fullM) 2 | %%% This code is a revised version of the Adam-Fusion algorithm. 3 | %%% M: the user-item rating matrix. This is the training set. The rows are 4 | %%% users, and the columns are items. The entries are ratings from users 5 | %%% on items. 6 | %%% TestData: this is the test set, in format of [userID, itemID, ratings]. 7 | %%% fullM: the imputed M, in which all the missing values in M have been 8 | %%% imputed with some prediction method. This can be done with any rating 9 | %%% prediction algorithm, e.g. user based CF or item based CF. 10 | %%% This fullM parameter is aiming at speed up the imputation process, 11 | %%% because Adam-Fusion will impute a large proportion 12 | %%% of the overall missing values. 13 | %%% Please note that, not all imputed values will be used. This fullM is 14 | %%% for efficient computation purposes only. 15 | %%% The code is free for academic usage. You can run it at your own risk. 16 | 17 | feature accel on 18 | 19 | %%% Adjust the following parameters to suit the training data. 20 | %%% The number of neighbours. 21 | para.neighK = 30; 22 | %%% The maxValue and minValue for ratings in current data set. 23 | para.maxValue = 5; 24 | para.minValue = 1; 25 | %%% The lambda parameter in Adam-Fusion. 26 | para.ourLamda = 0.4; 27 | 28 | [W] = PearsonCorrelation(M); 29 | itemW = PearsonCorrelation(M'); 30 | 31 | para.fullM = fullM; 32 | clear fullM; 33 | nanInd = find(isnan(para.fullM)); 34 | para.fullM(nanInd) = 0; 35 | fprintf('begin to do prediction. \n'); 36 | 37 | %%% Do prediction. 38 | testUser = size(TestData, 1); 39 | 40 | for testUserInd = 1:testUser 41 | para.fullM(TestData(testUserInd, 1), TestData(testUserInd, 2)) = 0; 42 | end 43 | 44 | para.originalM = M; 45 | 46 | [prediction] = adamFusion(M, W, itemW, TestData, para); 47 | 48 | finalPre = para.ourLamda * prediction.userBased + (1-para.ourLamda) * prediction.itemBased; 49 | 50 | maeAll = []; 51 | 52 | [tempNum temp] = size(finalPre); 53 | 54 | for neighInd = 1:tempNum 55 | [maeValue] = MAE(TestData(:, 3)', finalPre(neighInd, :)); 56 | maeAll = [maeAll maeValue]; 57 | end 58 | 59 | save('maeAll', 'maeAll'); 60 | return 61 | -------------------------------------------------------------------------------- /Adam/sources/pccVectorActUser.m: -------------------------------------------------------------------------------- 1 | function [newWVector] = pccVectorActUser(testUser, userKNN, M) 2 | 3 | userNum = length(userKNN); 4 | 5 | activeUserVector = M(testUser, :); 6 | 7 | newWVector = zeros(1, userNum); 8 | 9 | for userInd = 1:userNum 10 | tempW = 0; 11 | curUser = userKNN(userInd); 12 | 13 | if curUser ~= testUser 14 | curUserVector = M(curUser, :); 15 | 16 | inds = find(activeUserVector .* curUserVector); 17 | if isempty(inds) 18 | tempW = 0; 19 | else 20 | tempW = pccVectors(activeUserVector(inds), curUserVector(inds)); 21 | end 22 | end 23 | newWVector(userInd) = tempW; 24 | end 25 | 26 | 27 | return -------------------------------------------------------------------------------- /Adam/sources/pccVectors.m: -------------------------------------------------------------------------------- 1 | function sim = pccVectors(vectorA, vectorB) 2 | 3 | inds = find(vectorA.*vectorB); 4 | if isempty(inds) 5 | sim = 0; 6 | else 7 | avegi = sum(vectorA(inds))/length(inds); 8 | avegj = sum(vectorB(inds))/length(inds); 9 | 10 | fenzi = sum((vectorA(inds)-avegi).*(vectorB(inds)-avegj)); 11 | fenmu = sqrt(sum((vectorA(inds)-avegi).^2))*sqrt(sum((vectorB(inds)-avegj).^2)); 12 | 13 | if fenzi == 0 && fenmu == 0 14 | sim = 0; 15 | else 16 | sim = fenzi/fenmu; 17 | end 18 | end 19 | 20 | return -------------------------------------------------------------------------------- /Adam/sources/ssiUpdateSimMatrixActiveUser.m: -------------------------------------------------------------------------------- 1 | function [W] = ssiUpdateSimMatrixActiveUser(impM, W, userKNN, testUser, para) 2 | 3 | userKNNLen = length(userKNN); 4 | 5 | [newWVector] = pccVectorActUser(testUser, userKNN, impM); 6 | 7 | W(testUser, userKNN) = newWVector; 8 | W(userKNN, testUser) = newWVector; 9 | 10 | return -------------------------------------------------------------------------------- /CTR/CTR-manual.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulip-lab/open-code/afcc27a3cabf9b5658309b84a9940c8533a397ca/CTR/CTR-manual.pdf -------------------------------------------------------------------------------- /CTR/README.md: -------------------------------------------------------------------------------- 1 | # CTR 2 | --- 3 | 4 | | Field | Value | 5 | | --- | --- | 6 | | Title | CTR | 7 | | Type | Source Code | 8 | | Language | Matlab | 9 | | License | | 10 | | Status | Research Code | 11 | | Update Frequency | NO | 12 | | Date Published | 2011-01-31 | 13 | | Date Updated | 2019-01-31 | 14 | | Portal | https://github.com/tulip-lab/open-code | 15 | | URL | https://github.com/tulip-lab/open-code/tree/master/CTR| 16 | | Publisher |[TULIP Lab](http://www.tulip.org.au/) | 17 | | Point of Contact |[A/Prof. Gang Li](https://github.com/tuliplab) | 18 | 19 | This package (CTR) implemented the algorithm to generate targeted positive/negative rules and contrast among multiple datasets. 20 | 21 | The manual can be found here: [Manual](CTR-manual.pdf) 22 | 23 | --- 24 | ## Citations 25 | --- 26 | 27 | If you use it for a scientific publication, please include a reference to this paper. 28 | 29 | * Rob Law, Jia Rong, Huy Quan Vu, Gang Li, Andy Lee (2011). [Identifying Changes And Trends In Hong Kong Outbound Tourism](https://doi.org/10.1016/j.tourman.2010.09.011), **Tourism Management**, Volume 32, Issue 5, Pages 1106-1114, 2011. 30 | 31 | * Jia Rong, Huy Quan Vu, Rob Law, Gang Li (2011). [A Behavioral Analysis of Web Sharers and Browsers in Hong Kong using Targeted Association Rule Mining](https://doi.org/10.1016/j.tourman.2011.08.006), **Tourism Management**, 2011. 32 | 33 | `BibTex` information: 34 | 35 | @Article{LRVLL11J03, 36 | author = {Law, Rob and Rong, Jia and Vu, Huy Quan and Li, Gang and Lee, Hee Andy}, 37 | title = {{Identifying changes and trends in Hong Kong outbound tourism}}, 38 | journal = {Tourism Management}, 39 | year = {2011}, 40 | volume = {32}, 41 | pages = {1106--1114}, 42 | month = oct, 43 | issn = {02615177}, 44 | doi = {10.1016/j.tourman.2010.09.011}, 45 | } 46 | 47 | @Article{RVLL11J06, 48 | author = {Rong, Jia and Vu, Huy Quan and Law, Rob and Li, Gang}, 49 | title = {{A behavioral analysis of web sharers and browsers in Hong Kong using targeted association rule mining}}, 50 | journal = {Tourism Management}, 51 | year = {2011}, 52 | doi = {10.1016/j.tourman.2011.08.006}, 53 | } 54 | 55 | --- 56 | ## Requirements 57 | --- 58 | 59 | * Matlab 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /CTR/code/addItemSupp.m: -------------------------------------------------------------------------------- 1 | function [candL,candN] = addItemSupp(itemCandL,itemCandN,itemSuppL,itemSuppN) 2 | 3 | [lenL,dimL] = size(itemCandL); 4 | [lenN,dimN] = size(itemCandN); 5 | countL = 1; 6 | countN = 1; 7 | candL = {}; 8 | candN = {}; 9 | 10 | for i = 1: lenL 11 | for j = 1:dimL 12 | tempL{1,j} = itemCandL{i,j}; 13 | end 14 | candL{countL,1} = tempL; 15 | candL{countL,2} = itemSuppL{i,3}; 16 | countL = countL + 1; 17 | end 18 | for i = 1:lenN 19 | for j = 1:dimN 20 | tempN{1,j} = itemCandN{i,j}; 21 | end 22 | candN{countN,1} = tempN; 23 | candN{countN,2} = itemSuppN{i,3}; 24 | countN = countN + 1; 25 | end 26 | return -------------------------------------------------------------------------------- /CTR/code/calConfidence.m: -------------------------------------------------------------------------------- 1 | function confidence = calConfidence(eachgroupdata, examiningcandidate) 2 | 3 | if isempty(examiningcandidate) 4 | confidence = {}; 5 | return; 6 | end 7 | 8 | numRec = length(eachgroupdata); 9 | [lenL,dimL] = size(examiningcandidate); 10 | 11 | temp = {}; 12 | for i = 1:dimL-1 13 | temp{1,i} = examiningcandidate{1,i}; 14 | end 15 | 16 | CountCondiItem = 0; 17 | Countitem = 0; 18 | for j = 1:numRec 19 | num = 0; 20 | for m = 1:dimL 21 | if ismember(examiningcandidate{1,m},eachgroupdata(j,:)) 22 | num = num +1; 23 | end 24 | end 25 | if num == dimL; 26 | Countitem = Countitem +1; 27 | end 28 | 29 | [f,s] = size(temp); 30 | number = 0; 31 | for n = 1:s 32 | if ismember(temp{1,n},eachgroupdata(j,:)) 33 | number = number +1; 34 | end 35 | if number == s; 36 | CountCondiItem = CountCondiItem +1; 37 | end 38 | end 39 | end 40 | 41 | confidence = Countitem/CountCondiItem; 42 | 43 | 44 | 45 | return 46 | end 47 | -------------------------------------------------------------------------------- /CTR/code/calDemoSupp.m: -------------------------------------------------------------------------------- 1 | function itemSCI=calDemoSupp(record, itemSet) 2 | 3 | len = length(itemSet); 4 | numRec = length(record); 5 | 6 | for i = 4:len 7 | count = 0; 8 | supp = 0; 9 | for j = 1:numRec 10 | num = 0; 11 | k = length(itemSet{i,1}); 12 | for m = 2:k 13 | if ismember(itemSet{i,1}{1,m},record(j,:)) 14 | num = num +1; 15 | end 16 | end 17 | if num == (k-1); 18 | count = count +1; 19 | end 20 | end 21 | if count >0 22 | supp = count/numRec; 23 | end 24 | itemSCI{i,3}=count; 25 | itemSCI{i,4}=supp; 26 | i 27 | end 28 | return -------------------------------------------------------------------------------- /CTR/code/calInts1.m: -------------------------------------------------------------------------------- 1 | function itemInts = calInts1(L,targetSupp,record) 2 | % calculate interestingness of (X->Y) 3 | 4 | temp = {}; 5 | [len,dimL] = size(L{1,1}); 6 | lenL = length(L); 7 | lenT = length(targetSupp); 8 | 9 | % get attList for X 10 | for i = 1:lenL 11 | for j = 1:(dimL-1) 12 | temp{i,j} = L{i,j}; 13 | end 14 | end 15 | 16 | xSupp = calSupp(record,temp); % calculate support value for X 17 | 18 | % get support value for Y 19 | count = 1; 20 | for i = 1:lenL 21 | for j = 1:lenT 22 | if (L{i,dimL} == targetSupp{j,1}) 23 | ySupp{count,1} = targetSupp{j,1}; 24 | ySupp{count,2} = targetSupp{j,2}; 25 | ySupp{count,3} = targetSupp{j,3}; 26 | count = count + 1; 27 | end 28 | end 29 | end 30 | 31 | for i = 1:lenL 32 | itemInts{i,1} = abs(L{i,2}-xSupp{i,3}*ySupp{i,3}); 33 | end 34 | return 35 | 36 | -------------------------------------------------------------------------------- /CTR/code/calIntsConfL.m: -------------------------------------------------------------------------------- 1 | function [itemInts,itemConf] = calIntsConfL(candL,targetSupp,record) 2 | % calculate interestingness of (X->Y) 3 | 4 | temp = {}; 5 | [len,dimL] = size(candL{1,1}); 6 | [lenL,dimTT] = size(candL); 7 | [lenT,dimT] = size(targetSupp); 8 | count = 1; 9 | 10 | % get attList for X 11 | for i = 1:lenL 12 | for j = 1:(dimL-1) 13 | temp{1,j} = candL{i,1}{1,j}; 14 | end 15 | tempSupp = calXSupp(record,temp); % calculate support value for X 16 | xSupp(i,:) = tempSupp; 17 | 18 | % get support value for Y 19 | for j = 1:lenT 20 | if isequal(candL{i,1}{1,dimL},targetSupp{j,1}) 21 | ySupp{count,1} = targetSupp{j,1}; 22 | ySupp{count,2} = targetSupp{j,2}; 23 | ySupp{count,3} = targetSupp{j,3}; 24 | count = count + 1; 25 | end 26 | end 27 | 28 | % calculate interestingness of (X->Y) 29 | depend = candL{i,2}-xSupp{i,3}*ySupp{i,3} 30 | itemInts{i,1} = abs(depend); 31 | itemConf{i,1} = candL{i,2}; 32 | itemConf{i,2} = xSupp{i,3}; 33 | itemConf{i,3} = ySupp{i,3}; 34 | if depend > 0 35 | itemConf{i,4} = depend /(xSupp{i,3}*(1-ySupp{i,3})); 36 | else 37 | itemConf{i,4} = depend /(xSupp{i,3}*ySupp{i,3}); 38 | end 39 | end 40 | return 41 | -------------------------------------------------------------------------------- /CTR/code/calIntsConfN.m: -------------------------------------------------------------------------------- 1 | function [itemInts,itemConf] = calIntsConfN(candN,targetSupp,record) 2 | % calculate interestingness of (X->Y) 3 | 4 | temp = {}; 5 | [len,dimN] = size(candN{1,1}); 6 | [lenN,dimNN] = size(candN); 7 | [lenT,dimT] = size(targetSupp); 8 | count = 1; 9 | 10 | % get attList for X 11 | for i = 1:lenN 12 | for j = 1:(dimN-1) 13 | temp{i,j} = candN{i,1}{1,j}; 14 | end 15 | tempSupp = calXSupp(record,temp); % calculate support value for X 16 | xSupp(i,:) = tempSupp; 17 | 18 | % get support value for Y 19 | for j = 1:lenT 20 | if isequal(candN{i,1}{1,dimN},targetSupp{j,1}) 21 | ySupp{count,1} = targetSupp{j,1}; 22 | ySupp{count,2} = targetSupp{j,2}; 23 | ySupp{count,3} = targetSupp{j,3}; 24 | count = count + 1; 25 | end 26 | end 27 | 28 | xySupp = xSupp{i,3}-candN{i,2}; 29 | NySupp = 1-ySupp{i,3}; 30 | % calculate interestingness of (X->Y) 31 | depend = xySupp - xSupp{i,3}*NySupp 32 | itemInts{i,1} = abs(depend); 33 | itemConf{i,1} = xySupp; 34 | itemConf{i,2} = xSupp{i,3}; 35 | itemConf{i,3} = NySupp; 36 | if depend > 0 37 | itemConf{i,4} = -depend /(xSupp{i,3}*(1-NySupp)); 38 | else 39 | itemConf{i,4} = -depend /(xSupp{i,3}*NySupp); 40 | end 41 | end 42 | return 43 | -------------------------------------------------------------------------------- /CTR/code/calSupp.m: -------------------------------------------------------------------------------- 1 | function itemSupp=calSupp(record, itemSet) 2 | 3 | [len,dim] = size(itemSet); 4 | numRec = length(record); 5 | 6 | for i = 1:len 7 | count = 0; 8 | supp = 0; 9 | for j = 1:numRec 10 | num = 0; 11 | [l,k] = size(itemSet); 12 | for m = 1:k 13 | if ismember(itemSet{i,m},record(j,:)) 14 | num = num +1; 15 | end 16 | end 17 | if num == k; 18 | count = count +1; 19 | end 20 | end 21 | if count >0 22 | supp = count/numRec; 23 | end 24 | itemSupp{i,1} = itemSet(i,:); 25 | itemSupp{i,2}=count; 26 | itemSupp{i,3}=supp; 27 | end 28 | return -------------------------------------------------------------------------------- /CTR/code/calSuppOne.m: -------------------------------------------------------------------------------- 1 | function itemSCI=calSuppOne(record, itemSet) 2 | 3 | len = length(itemSet); 4 | numRec = length(record); 5 | 6 | for i = 1:len 7 | count = 0; 8 | supp = 0; 9 | for j = 1:numRec 10 | num = 0; 11 | if ismember(itemSet{i,1},record(j,:)) 12 | num = num +1; 13 | end 14 | if num == 1; 15 | count = count +1; 16 | end 17 | end 18 | if count >0 19 | supp = count/numRec; 20 | end 21 | itemSCI{i,1}=itemSet{i,1}; 22 | itemSCI{i,2}=count; 23 | itemSCI{i,3}=supp; 24 | end 25 | return -------------------------------------------------------------------------------- /CTR/code/calXSupp.m: -------------------------------------------------------------------------------- 1 | function itemSupp=calXSupp(record, itemSet) 2 | 3 | numRec = length(record); 4 | count = 0; 5 | supp = 0; 6 | for j = 1:numRec 7 | num = 0; 8 | [l,k] = size(itemSet); 9 | for m = 1:k 10 | if ismember(itemSet{l,m},record(j,:)) 11 | num = num +1; 12 | end 13 | end 14 | if num == k; 15 | count = count +1; 16 | end 17 | end 18 | if count >0 19 | supp = count/numRec; 20 | end 21 | itemSupp{1,1} = itemSet(1,:); 22 | itemSupp{1,2}=count; 23 | itemSupp{1,3}=supp; 24 | 25 | return -------------------------------------------------------------------------------- /CTR/code/findDecomposition.m: -------------------------------------------------------------------------------- 1 | function founddecomposition = findDecomposition(FSDeviation, examingCand) 2 | 3 | founddecomposition={}; 4 | [rowSD, colSD] = size(FSDeviation); 5 | numberofsuprisingdeviation = 1; 6 | 7 | for colCan =1:length(examingCand)-1 8 | result{1,colCan} = 0; 9 | end 10 | %find the decomposition of examining itemset from foundeviation such that 11 | %union of decomposition is that itemset, larger itemset have higher 12 | %priority. 13 | while colSD>0 14 | levelofFSD = FSDeviation{1,colSD}; 15 | [rowlevel,collevel] = size(levelofFSD); 16 | for rowsd = 1:rowlevel 17 | examingSD = levelofFSD{rowsd,1}; 18 | t = ismember(examingSD,examingCand); 19 | numberoft0 = 0; 20 | for tt = 1:length(t) 21 | if (t(1,tt) == 0) 22 | numberoft0 = numberoft0 +1; 23 | end 24 | end 25 | 26 | if (numberoft0==0) 27 | for examSD= 1:length(examingSD)-1 28 | for examCD = 1:length(examingCand)-1 29 | itemsSD = examingSD{1,examSD}; 30 | itemsCD = examingCand{1,examCD}; 31 | if(isequal(itemsSD,itemsCD)==1 && result{1,examCD} == 0) 32 | result{1,examCD} = 1; 33 | founddecomposition{numberofsuprisingdeviation,1}= examingSD; 34 | numberofsuprisingdeviation = numberofsuprisingdeviation +1; 35 | end 36 | end 37 | end 38 | end 39 | 40 | end 41 | colSD=colSD-1; 42 | end 43 | return 44 | -------------------------------------------------------------------------------- /CTR/code/findSuprisingDeviation.m: -------------------------------------------------------------------------------- 1 | function SuprisingDeviation = findSuprisingDeviation(candidateitemset,groupsdataset,m_surprisingThreshold,VAL) 2 | 3 | % candidateitemset = NeGaTiveList; 4 | % groupsdataset=groups; 5 | % m_surprisingThreshold=SurprisingThreshold; 6 | % VAL =value; 7 | 8 | 9 | [rowCan,colCan] = size(candidateitemset); 10 | foundedSuprisingDeviation = {candidateitemset{1,1}}; 11 | forlevel1 = foundedSuprisingDeviation{1,1}; 12 | 13 | for eachcan = 1:length(forlevel1) 14 | eachcandi = forlevel1{eachcan,1}; 15 | Level1SD{eachcan,1} = eachcandi; 16 | for p =1:length(VAL) 17 | eGdataset = groupsdataset{1,p}; 18 | ecSupp = calSupp(eGdataset,eachcandi); 19 | Level1SD{eachcan,p+1} = ecSupp{1,3}; 20 | end 21 | 22 | end 23 | 24 | SuprisingDeviation{1,1} = Level1SD; 25 | %for each level of the candidateitemset 26 | for n =2: rowCan 27 | clear levelcandidate; 28 | levelcandidate = candidateitemset{n,1}; 29 | [rowLev,colLev] = size(levelcandidate); 30 | numberofselected = 1; 31 | %for each candidate in each level of candiateitemset 32 | selectedCandidate = {0}; 33 | for l = 1:rowLev 34 | examingcandidate = levelcandidate{l,1}; 35 | clear decomposition; 36 | decomposition = findDecomposition(foundedSuprisingDeviation,examingcandidate); 37 | 38 | [rowdecom,columdecom] = size(decomposition); 39 | 40 | %calculate support value for this examining item set for each group 41 | for p =1:length(VAL) 42 | 43 | eGdataset = groupsdataset{1,p}; 44 | 45 | ecSupp = calSupp(eGdataset,examingcandidate); 46 | esSuppingvalue{1,p} = ecSupp{1,3}; 47 | end 48 | %-------------------------------------------------------------- 49 | %if there is some decomposition of this examiming candidate we check to decide if it is 50 | %surprising or not. if there is no decomposition then it is 51 | %surprising 52 | 53 | if (isempty(decomposition)==0) 54 | for p =1:length(VAL) 55 | expectedSupports{1,p} = 1; 56 | end 57 | 58 | %calculate expected support for the decomposition of each 59 | %groups 60 | for p =1:length(VAL) 61 | eachGroup = groupsdataset{1,p}; 62 | 63 | for decom = 1:rowdecom 64 | eachcomposition = decomposition{decom,1}; 65 | eachCompoSupp= calSupp(eachGroup,eachcomposition); 66 | 67 | expectedSupports{1,p} = expectedSupports{1,p} * eachCompoSupp{1,3}; 68 | end 69 | end 70 | isSurprisingList = isSurprising(esSuppingvalue,expectedSupports,m_surprisingThreshold); 71 | else 72 | isSurprisingList=1; 73 | end 74 | %------------------------------------------------------------- 75 | if (isSurprisingList==1) 76 | selectedCandidate{numberofselected,1} = examingcandidate; 77 | 78 | for p =1:length(VAL) 79 | eachrecord = groupsdataset{1,p}; 80 | confidence = calConfidence(eachrecord, examingcandidate); 81 | selectedCandidate{numberofselected,p+1} = confidence; 82 | end 83 | numberofselected=numberofselected+1; 84 | end 85 | end 86 | 87 | 88 | SuprisingDeviation{1,n} = selectedCandidate; 89 | foundedSuprisingDeviation(1,n) = {selectedCandidate(:,1)}; 90 | 91 | end 92 | 93 | return 94 | -------------------------------------------------------------------------------- /CTR/code/genItem.m: -------------------------------------------------------------------------------- 1 | function A = genItem(attValue) 2 | 3 | 4 | A = {}; 5 | len = length(attValue{1,1}); 6 | for i = 1:len 7 | A{i,1}=[attValue{1,1}(1,i)]; 8 | end 9 | count = length(A); 10 | dim = length(attValue); 11 | for i = 2:dim 12 | lenA = length(A); 13 | leni = length(attValue{i,:}); 14 | for j = 1:lenA 15 | for k = 1:leni 16 | A{end+1,:}=[A{j,1}(1,:),attValue{i,1}(1,k)]; 17 | count = count +1 18 | end 19 | end 20 | end -------------------------------------------------------------------------------- /CTR/code/genItemCand.m: -------------------------------------------------------------------------------- 1 | function itemCand = genItemCand(attList,targetList,k) 2 | 3 | 4 | temp = {}; 5 | index = 0; 6 | n = k-1; 7 | 8 | list = nchoosek(attList,n); 9 | 10 | len = length(list); 11 | for i = 1:len 12 | count = 0; 13 | for j = 1:n-1 14 | if (isequal(list{i,j}(1,1),list{i,j+1}(1,1))) 15 | count = count + 1; 16 | end 17 | end 18 | if count == 0 19 | index = index +1; 20 | temp(index,:)=list(i,:); 21 | end 22 | end 23 | 24 | 25 | % if ((k-1)>1) 26 | % for i = 1:(len-k+2) 27 | % for j = (i+1):len 28 | % temp{count,1}=attList{i,1}; 29 | % for n = 2:k-1 30 | % temp{count,n}=attList{j,1}; 31 | % end 32 | % count = count + 1; 33 | % end 34 | % 35 | % end 36 | % else 37 | % temp = attList; 38 | % end 39 | 40 | lenTg = length(targetList); 41 | [rowtem,coltem] = size(temp); 42 | lenTp = rowtem; 43 | num = 1; 44 | itemCand = {}; 45 | for i = 1:lenTg 46 | % for j = 1:(lenTp-1) 47 | % for n = 1:(k-1) 48 | % itemCand{num,n}=temp{j,n}; 49 | % end 50 | % itemCand{num,k}= targetList{i,1}; 51 | % num = num + 1; 52 | % end 53 | for j = 1:(lenTp) 54 | for m = 1:n 55 | itemCand{num,m} = temp{j,m}; 56 | end 57 | itemCand{num,k} = targetList{i,1}; 58 | num = num+1; 59 | end 60 | 61 | end 62 | 63 | return 64 | -------------------------------------------------------------------------------- /CTR/code/genItemCandOne.m: -------------------------------------------------------------------------------- 1 | function itemCandOne = genItemCandOne(attValue) 2 | % generate 1-item candidate set 3 | 4 | count = 0; 5 | lenA = length(attValue); 6 | 7 | for i = 1:lenA 8 | numAttVal= length(attValue{i,1}); 9 | temp=attValue{i,1}; 10 | for j = 1:numAttVal 11 | count = count +1; 12 | itemCandOne(count,:) = {temp{1,j}}; 13 | end 14 | end 15 | return -------------------------------------------------------------------------------- /CTR/code/genL.m: -------------------------------------------------------------------------------- 1 | function L = genL(candL,itemInts,itemConf,minInts) 2 | 3 | [lenCL,dimCL] = size(candL); 4 | count = 1; 5 | L={}; 6 | 7 | for i = 1:lenCL 8 | if (itemInts{i,1}>=minInts) 9 | L{count,1} = candL{i,1}; 10 | L{count,2} = candL{i,2}; 11 | L{count,3} = itemInts{i,1}; 12 | L{count,4} = itemConf{i,4}; 13 | count = count + 1; 14 | end 15 | end 16 | return -------------------------------------------------------------------------------- /CTR/code/genTestL.m: -------------------------------------------------------------------------------- 1 | function L = genTestL(candL,itemInts,itemConf) 2 | 3 | [lenCL,dimCL] = size(candL); 4 | count = 1; 5 | L={}; 6 | 7 | for i = 1:lenCL 8 | L{count,1} = candL{i,1}; 9 | L{count,2} = candL{i,2}; 10 | L{count,3} = itemInts{i,1}; 11 | L{count,4} = itemConf{i,4}; 12 | count = count + 1; 13 | end 14 | return -------------------------------------------------------------------------------- /CTR/code/generateGroup.m: -------------------------------------------------------------------------------- 1 | function [groups,value,record] = generateGroup(data,index,numData,dimData) 2 | 3 | record = {}; 4 | 5 | for i = 1:numData-1 6 | record(i,:) = {data{i+1,2:dimData}}; 7 | end 8 | 9 | [numRec, dimRec] = size(record); % total numbers of the data instances & dimensions 10 | 11 | % extract the data of each group------------------------------------------- 12 | 13 | [numYear, dimYear] = size(index); 14 | numberofYear = 1; 15 | value{1,1}=index(1,:); 16 | yearValue = index(1,:); 17 | for k= 2:numYear 18 | if(isequal(yearValue,index(k,:))==0) 19 | yearValue=index(k,:); 20 | numberofYear = numberofYear+1; 21 | value{1,numberofYear}=index(k,:); 22 | end 23 | end 24 | 25 | groups = {}; 26 | for inde = 1:length(value) 27 | countyearrecord = 1; 28 | group = {}; 29 | for yearindex=1:numYear 30 | if index(yearindex,1) == value{1,inde} 31 | group(countyearrecord,:) = {record{yearindex,1:dimRec}}; 32 | countyearrecord = countyearrecord + 1; 33 | end 34 | end 35 | groups(1,inde) = {group}; %this is the data of each group seperated 36 | clear group; 37 | end 38 | 39 | return 40 | end -------------------------------------------------------------------------------- /CTR/code/generateLIST.m: -------------------------------------------------------------------------------- 1 | function [GROUPpositivelist,GROUPnegativelist,GROUPpone] = generateLIST(itemCand,value,finalitemPONElist) 2 | 3 | numberofpositivedata = 1; 4 | numterofnegativedata = 1; 5 | numberofpone = 1; 6 | [rowitemOneSupp, colitemOneSupp] = size(itemCand); 7 | GROUPpositivelist = {'x'}; 8 | GROUPnegativelist = {'x'}; 9 | GROUPpone = {'x'}; 10 | for ite = 1:rowitemOneSupp 11 | numberofnone1 = 0; 12 | numberofnone0 = 0; 13 | numberofx=0; 14 | examitemset = finalitemPONElist{ite,1}; 15 | %get the positive list 16 | for onegroup = 1:length(value) 17 | 18 | valuePoOrNe = finalitemPONElist{ite,onegroup+1}; 19 | 20 | if valuePoOrNe == 0 || valuePoOrNe == 'x' 21 | numberofnone1= numberofnone1+1; 22 | end 23 | if valuePoOrNe == 'x' 24 | numberofx =numberofx +1; 25 | end 26 | end 27 | 28 | if numberofnone1 == 0 29 | GROUPpositivelist{numberofpositivedata,1} = examitemset;% get only the positive item set (for all group) to generate itemset later on. 30 | numberofpositivedata = numberofpositivedata+1; 31 | end 32 | %get the negative list 33 | for onegroup = 1:length(value) 34 | 35 | valuePoOrNe = finalitemPONElist{ite,onegroup+1}; 36 | 37 | if valuePoOrNe == 1 || valuePoOrNe == 'x' 38 | numberofnone0= numberofnone0+1; 39 | end 40 | if valuePoOrNe == 'x' 41 | numberofx =numberofx +1; 42 | end 43 | 44 | end 45 | 46 | if numberofnone0 == 0 47 | GROUPnegativelist{numterofnegativedata,1} = examitemset;% get only the positive item set (for all group) to generate itemset later on. 48 | numterofnegativedata = numterofnegativedata+1; 49 | end 50 | 51 | 52 | if (numberofnone0>0 && numberofnone1>0) 53 | if (numberofx == 0) 54 | GROUPpone{numberofpone,1} = examitemset; 55 | numberofpone = numberofpone+1; 56 | end 57 | end 58 | 59 | 60 | end 61 | return 62 | end -------------------------------------------------------------------------------- /CTR/code/generatePONElist.m: -------------------------------------------------------------------------------- 1 | function finalitemPONE = generatePONElist(itemOneSupp,groups,postiveitem,negativeitem) 2 | 3 | [rowitemOneSupp, colitemOneSupp] = size(itemOneSupp); 4 | 5 | finalitemPONE = {}; 6 | for ite = 1:rowitemOneSupp 7 | examiningitem{1,1} = itemOneSupp{ite,1}; 8 | finalitemPONE{ite,1} = examiningitem; 9 | 10 | for dataset = 1:length(groups) 11 | 12 | postiveitemsetinthisgroup = postiveitem{1,dataset}; 13 | negativeitemsetinthisgroup = negativeitem{1,dataset}; 14 | 15 | [rowofthisgroup, colofthisgroup] = size(postiveitemsetinthisgroup); 16 | [rowofingroup, colofingroup] = size(negativeitemsetinthisgroup); 17 | 18 | for row = 1:rowofthisgroup 19 | examiningpositive = postiveitemsetinthisgroup{row,1}; 20 | if (isequal(examiningitem,examiningpositive) == 1) 21 | finalitemPONE{ite,dataset+1} = 1 ; 22 | end 23 | 24 | end 25 | 26 | for rowne = 1: rowofingroup 27 | examiningnegative = negativeitemsetinthisgroup{rowne,1}; 28 | if (isequal(examiningitem,examiningnegative) ==1) 29 | finalitemPONE{ite,dataset+1} = 0;% table of positive and negative for each one cadidate item set 30 | end 31 | end 32 | end 33 | end 34 | return 35 | end -------------------------------------------------------------------------------- /CTR/code/generatePONEset.m: -------------------------------------------------------------------------------- 1 | function [positiveset,negativeset] = generatePONEset(value,groups,itemCand,minSupp,minInts,targetSupp,k) 2 | 3 | positiveset = {}; 4 | negativeset = {}; 5 | %find positive and negative itemset from generated itemsets. 6 | for dataset = 1:length(value) 7 | eachgroup = groups{1,dataset}; 8 | %calculate support each item set for each group. 9 | clear itemSupp; 10 | itemSupp = calSupp(eachgroup,itemCand); 11 | %save group support in a list. 12 | 13 | clear candL; 14 | clear candN; 15 | %base on support value find positive and negative items 16 | [candL,candN]=selectItem(itemCand,itemSupp,minSupp); 17 | 18 | 19 | % calculate interestingness for each itemset 20 | clear itemIntsL; 21 | clear itemIntsN; 22 | clear itemConfL; 23 | clear itemConfN; 24 | if(isempty(candL) ==0) 25 | [itemIntsL,itemConfL] = calIntsConfL(candL,targetSupp,eachgroup); 26 | else 27 | itemIntsL = {}; 28 | itemConfL = {}; 29 | end 30 | if(isempty(candN) == 0) 31 | [itemIntsN,itemConfN] = calIntsConfN(candN,targetSupp,eachgroup); 32 | else 33 | itemIntsN = {}; 34 | itemConfN = {}; 35 | end 36 | % select interested itemsets 37 | clear L; 38 | clear N; 39 | L = genL(candL,itemIntsL,itemConfL,minInts); 40 | N = genL(candN,itemIntsN,itemConfN,minInts); 41 | %save positive and negative for each group is a list. 42 | positiveset(k-1,dataset) = {L}; 43 | negativeset(k-1,dataset) = {N}; 44 | end 45 | return 46 | end 47 | -------------------------------------------------------------------------------- /CTR/code/generatePoList.m: -------------------------------------------------------------------------------- 1 | function positivelist = generatePoList(itemOneSupp,finalitemPONE,value) 2 | 3 | numberofpositivedata = 1; 4 | positivelist = {}; 5 | [rowitemOneSupp, colitemOneSupp] = size(itemOneSupp); 6 | for ite = 1:rowitemOneSupp 7 | numberofzero = 0; 8 | examitemset = finalitemPONE{ite,1}; 9 | for onegroup = 1:length(value) 10 | 11 | valuePoOrNe = finalitemPONE{ite,onegroup+1}; 12 | 13 | if valuePoOrNe == 0 14 | numberofzero= numberofzero+1; 15 | end 16 | end 17 | 18 | if numberofzero == 0 19 | positivelist{numberofpositivedata,1} = examitemset;% get only the positive item set (for all group) to generate itemset later on. 20 | numberofpositivedata = numberofpositivedata+1; 21 | end 22 | 23 | end 24 | return 25 | end 26 | -------------------------------------------------------------------------------- /CTR/code/generatefinalPONElist.m: -------------------------------------------------------------------------------- 1 | function finalitemPONElist = generatefinalPONElist(itemCand,groups,positiveset,negativeset,k) 2 | 3 | finalitemPONElist = {}; 4 | [rowitemOneSupp, colitemOneSupp] = size(itemCand); 5 | for ite = 1:rowitemOneSupp 6 | examiningitemsets= {itemCand{ite,:}}; 7 | finalitemPONElist(ite,1) = {examiningitemsets}; 8 | postiveitemsets = {}; 9 | negativeitemsets = {}; 10 | for dataset = 1:length(groups) 11 | finalitemPONElist(ite,dataset + 1) = {'x'}; 12 | 13 | postiveitemsets = positiveset{k-1,dataset}; 14 | negativeitemsets = negativeset{k-1,dataset}; 15 | 16 | [rowofthisgroup, colofthisgroup] = size(postiveitemsets); 17 | [rowofingroup, colofingroup] = size(negativeitemsets); 18 | if (~isempty(postiveitemsets)) 19 | for row = 1:rowofthisgroup 20 | examiningpositiveset = postiveitemsets{row,1}; 21 | if (isequal(examiningitemsets,examiningpositiveset) == 1) 22 | finalitemPONElist(ite,dataset+1) = {1} ; 23 | end 24 | 25 | end 26 | end 27 | if (~isempty(negativeitemsets)) 28 | for rowne = 1: rowofingroup 29 | examiningnegativeset = negativeitemsets{rowne,1}; 30 | if (isequal(examiningitemsets,examiningnegativeset) ==1) 31 | finalitemPONElist(ite,dataset+1) = {0};% table of positive and negative for each one cadidate item set 32 | end 33 | end 34 | end 35 | end 36 | end 37 | return 38 | end 39 | -------------------------------------------------------------------------------- /CTR/code/getAttList.m: -------------------------------------------------------------------------------- 1 | function attList = getAttList(L) 2 | 3 | if isempty(L) 4 | attList = {}; 5 | return; 6 | end 7 | 8 | [lenL,dimL] = size(L); 9 | temp = {}; 10 | attList = {}; 11 | for i = 1:lenL 12 | lenA = length(L{i,1}); 13 | for j = 1:(lenA-1) 14 | temp(i,j)=L{i,1}(1,j); 15 | end 16 | end 17 | 18 | 19 | [lenV,dimV] = size(temp); 20 | for i = 1:dimV 21 | attList(i,1)={temp{1,i}}; 22 | end 23 | count = dimV; 24 | 25 | for i = 2:lenV 26 | for j = 1:dimV 27 | if (~ismember(temp{i,j},attList)) 28 | count = count +1; 29 | attList(count,1)={temp{i,j}}; 30 | end 31 | end 32 | end 33 | attList = sort(attList); 34 | 35 | % tempAtt = getAttValue(temp); 36 | % lenV = length(tempAtt{1,1}); 37 | 38 | 39 | % 40 | % countR = 1; 41 | % countC = 1; 42 | % attList{1,1}={tempAtt{1,1}{1,1}}; 43 | % for i = 2:lenV 44 | % if ~isequal(tempAtt{1,1}{1,i-1}(1,1),tempAtt{1,1}{1,i}(1,1)) 45 | % countR = countR + 1; 46 | % attList{countR,1}{1,1}=tempAtt{1,1}{1,i}; 47 | % countC = 1; 48 | % else 49 | % countC = countC + 1; 50 | % attList{countR,1}{1,countC}=tempAtt{1,1}{1,i}; 51 | % end 52 | % end 53 | 54 | 55 | return 56 | 57 | -------------------------------------------------------------------------------- /CTR/code/getAttValue.m: -------------------------------------------------------------------------------- 1 | function [attValue, numValue] = getAttValue(record) 2 | % get attribute value function 3 | % input: data records 4 | % output: attribute values 5 | 6 | [numRec, dimRec] = size(record); 7 | 8 | numValue = 0; 9 | 10 | for i =1:dimRec 11 | count = 1; 12 | clear Att; 13 | for j = 1:numRec 14 | if(~strcmp(record{j,i},'NaN')) 15 | temp = record{j,i}; 16 | Att(1,count)={temp}; 17 | count = count +1; 18 | end 19 | end 20 | 21 | num = 1; 22 | temp=Att{1,1}; 23 | value(1,1)={temp}; 24 | for k=2:length(Att) 25 | if(isequal(temp,Att{1,k})==0 && ismember(Att{1,k},value)==0) 26 | temp=Att{1,k}; 27 | if ~strcmp(temp,'NaN') % discard 'NaN' value 28 | num = num+1; 29 | value(1,num)={temp}; 30 | end 31 | end 32 | end 33 | 34 | value = sort(value); 35 | attValue(i,1)={value}; 36 | clear value; 37 | numValue = numValue + count; 38 | end 39 | return -------------------------------------------------------------------------------- /CTR/code/getCand.m: -------------------------------------------------------------------------------- 1 | function itemcandL = getCand(candPosR,n) 2 | 3 | itemcandL = {}; 4 | 5 | [len,dim]=size(candPosR{n,1}); 6 | 7 | for i = 1:len 8 | for j = 1:(n+1) 9 | itemcandL{i,j} = candPosR{n,1}{i,1}{1,j}; 10 | end 11 | end 12 | 13 | return -------------------------------------------------------------------------------- /CTR/code/getCond.m: -------------------------------------------------------------------------------- 1 | function [cond,label] = getCond(candR) 2 | 3 | cond = {}; 4 | label = {}; 5 | temp = {}; 6 | 7 | 8 | [len, dim] = size(candR); 9 | 10 | for i = 1:len 11 | [lenR,dimR] = size(candR{i,1}); 12 | count = 1; 13 | for j = 1:lenR 14 | lenN = length(candR{i,1}{j,1}); 15 | for n = 1:(lenN-1) 16 | temp{count,n}=candR{i,1}{j,1}{1,n}; 17 | end 18 | temp{count,lenN+1} = candR{i,1}{j,1}{1,lenN}; 19 | temp{count,lenN+2} = candR{i,1}{j,4}; 20 | count = count +1; 21 | end 22 | 23 | end 24 | return -------------------------------------------------------------------------------- /CTR/code/getItemSet.m: -------------------------------------------------------------------------------- 1 | function C = getItemSet(A,B) 2 | 3 | lenA = length(A); 4 | lenB = length(B); 5 | 6 | count = 1; 7 | for i = 1:lenA 8 | for j = 1:lenB 9 | temp=B{1,j}; 10 | C{count,1}=[A{i,1},temp]; 11 | count = count+1; 12 | end 13 | end 14 | -------------------------------------------------------------------------------- /CTR/code/getRule.m: -------------------------------------------------------------------------------- 1 | function c = getRule(a) 2 | 3 | count = 1; 4 | c = {}; 5 | len = length(a); 6 | 7 | for i = 1:len 8 | [lenR,dimR] = size(a{i,1}); 9 | for j = 1:lenR 10 | lenN = length(a{i,1}{j,1}); 11 | for n = 1:(lenN-1) 12 | c{count,n}=a{i,1}{j,1}{1,n}; 13 | end 14 | c{count,lenN}='->'; 15 | c{count,lenN+1} = a{i,1}{j,1}{1,lenN}; 16 | c{count,lenN+2}=a{i,1}{j,4}; 17 | count = count +1; 18 | end 19 | end 20 | return -------------------------------------------------------------------------------- /CTR/code/isSurprising.m: -------------------------------------------------------------------------------- 1 | function suprisinglist = isSurprising(CandiSupp,ESupportsofDecom,SurpThreshold) 2 | 3 | % examiningCand=examingcandidate; 4 | %dataset=groupsdataset; 5 | %ESupportsofDecom= expectedSupports; 6 | %SurpThreshold=m_surprisingThreshold; 7 | 8 | average = 0; 9 | suprisinglist = 0; 10 | 11 | for esl = 1:length(ESupportsofDecom) 12 | dif = ESupportsofDecom{1,esl} - CandiSupp{1,esl}; 13 | diff = abs(dif); 14 | average = average+ diff; 15 | end 16 | average=average/length(ESupportsofDecom); 17 | 18 | if(average>=SurpThreshold) 19 | suprisinglist = 1; 20 | end 21 | return -------------------------------------------------------------------------------- /CTR/code/sample.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulip-lab/open-code/afcc27a3cabf9b5658309b84a9940c8533a397ca/CTR/code/sample.xlsx -------------------------------------------------------------------------------- /CTR/code/savetofile.m: -------------------------------------------------------------------------------- 1 | function f = savetofile(deviation,filename,VAL) 2 | 3 | %filename = 't.xls'; 4 | %deviation = SurprisingPo; 5 | save ={}; 6 | for i=1:length(deviation) 7 | data = deviation{1,i}; 8 | clear save; 9 | 10 | [rowdata, coldata] = size(data); 11 | for l = 1:rowdata 12 | clear itemset; 13 | itemset = data{l,1}; 14 | for g =1:length(itemset) 15 | save{l,g} = itemset{1,g}; 16 | end 17 | 18 | for p =1:length(VAL) 19 | save{l,p+length(itemset)} = data{l,p+1}*100; 20 | end 21 | 22 | end 23 | xlswrite(filename, save,i); 24 | end 25 | f = 1; 26 | 27 | return -------------------------------------------------------------------------------- /CTR/code/savetofile2.m: -------------------------------------------------------------------------------- 1 | function f = savetofile(deviation,filename) 2 | 3 | %filename = 't.xls'; 4 | %deviation = SurprisingPo; 5 | save ={}; 6 | for i=1:length(deviation) 7 | data = deviation{1,i}; 8 | clear save; 9 | 10 | [rowdata, coldata] = size(data); 11 | for l = 1:rowdata 12 | clear itemset; 13 | itemset = data{l,1}; 14 | for g =1:length(itemset) 15 | save{l,g} = itemset{1,g}; 16 | end 17 | 18 | for p =1:length(VAL) 19 | save{l,p+length(itemset)} = data{l,p+1}*100; 20 | end 21 | 22 | end 23 | xlswrite(filename, save,i); 24 | end 25 | f = 1; 26 | 27 | return -------------------------------------------------------------------------------- /CTR/code/selectItem.m: -------------------------------------------------------------------------------- 1 | function [candL,candN] = selectItem(itemCand,itemSupp,minSupp) 2 | 3 | [len,dim] = size(itemCand); 4 | countL = 1; 5 | countN = 1; 6 | candL = {}; 7 | candN = {}; 8 | 9 | for i = 1: len 10 | if (itemSupp{i,3}>=minSupp) 11 | for j = 1:dim 12 | tempL{1,j} = itemCand{i,j}; 13 | end 14 | candL{countL,1} = tempL; 15 | candL{countL,2} = itemSupp{i,3}; 16 | countL = countL + 1; 17 | else 18 | for j = 1:dim 19 | tempN{1,j} = itemCand{i,j}; 20 | end 21 | candN{countN,1} = tempN; 22 | candN{countN,2} = itemSupp{i,3}; 23 | countN = countN + 1; 24 | end 25 | end 26 | return -------------------------------------------------------------------------------- /CTR/code/selectItemOne.m: -------------------------------------------------------------------------------- 1 | function [L1,N1] = selectItemOne(itemCandOne, itemOneSupp,minSupp) 2 | 3 | len = length(itemCandOne); 4 | countL = 1; 5 | countN = 1; 6 | 7 | for i = 1: len 8 | if (itemOneSupp{i,2}>=minSupp) 9 | L1{countL,1} = itemCandOne{i,1}; 10 | L1{countL,2} = itemOneSupp{i,2}; 11 | countL = countL + 1; 12 | else 13 | N1{countN,1} = itemCandOne{i,1}; 14 | N1{countN,2} = itemOneSupp{i,2}; 15 | countN = countN + 1; 16 | end 17 | end 18 | return -------------------------------------------------------------------------------- /CTR/code/writeXitem.m: -------------------------------------------------------------------------------- 1 | function item=writeXitem(attValue,x,count) 2 | 3 | k = x; 4 | 5 | for i = 1: length(attValue{k,1}) 6 | item{count,1} = attValue{k,1}{1,i}; 7 | count = count+1; 8 | end 9 | -------------------------------------------------------------------------------- /DLM/DLM.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | from keras.layers import * 4 | from keras.layers.core import * 5 | from keras.models import * 6 | 7 | from keras.layers import Dense 8 | from keras.layers import LSTM 9 | 10 | from keras import initializers 11 | from keras import optimizers 12 | from keras.callbacks import ReduceLROnPlateau 13 | 14 | from keras.callbacks import EarlyStopping 15 | from keras.callbacks import ReduceLROnPlateau 16 | 17 | 18 | def attention_block(inputs,TIME_STEPS,INPUT_DIM): 19 | 20 | input_dim = int(inputs.shape[2]) 21 | a = Permute((2, 1))(inputs) 22 | a = Dense(TIME_STEPS, activation='sigmoid',use_bias=True,kernel_initializer='glorot_normal')(a) 23 | a = Dense(TIME_STEPS, activation='softmax')(a) 24 | a_probs = Permute((2, 1), name='attention_vec')(a) 25 | output_attention_mul = multiply([inputs, a_probs], name='attention_mul') 26 | return output_attention_mul 27 | 28 | def model_attention_applied_before_lstm(TIME_STEPS,INPUT_DIM,lstm_unit,drop_rate,dense_unit): 29 | 30 | inputs = Input(shape=(TIME_STEPS, INPUT_DIM,)) 31 | attention_mul = attention_block(inputs,TIME_STEPS,INPUT_DIM) 32 | attention_mul = LSTM(lstm_unit, return_sequences=True)(attention_mul) 33 | attention_mul = Flatten()(attention_mul) 34 | dropout = Dropout(drop_rate)(attention_mul) 35 | output = Dense(dense_unit, activation='tanh',kernel_initializer='glorot_normal')(attention_mul) 36 | output = Dense(1, activation='sigmoid',kernel_initializer='he_normal',)(output) 37 | model = Model(input=[inputs], output=output) 38 | return model 39 | 40 | 41 | def build_model(tranin_X,train_Y,lstm_unit,drop_rate,dense_unit,batch_size,epochs): 42 | 43 | outputs = train_Y.reshape(train_Y.shape[0],1) 44 | TIME_STEPS = tranin_X.shape[1] 45 | INPUT_DIM = tranin_X.shape[2] 46 | attention_lstm__model = model_attention_applied_before_lstm(TIME_STEPS, 47 | INPUT_DIM, 48 | lstm_unit, 49 | drop_rate, 50 | dense_unit) 51 | 52 | 53 | attention_lstm__model.compile(loss = 'mae',optimizer= "Adam") #"Adam" 54 | rlrop = ReduceLROnPlateau(monitor='val_loss', factor=0.01, patience=5) 55 | 56 | attention_lstm__model.fit([tranin_X], 57 | outputs, 58 | epochs=epochs, 59 | batch_size=batch_size, 60 | callbacks=[rlrop], 61 | validation_split = 0.1 62 | #validation_data=([lstmtest_X],test_Y.reshape(test_Y.shape[0],1)) 63 | ) 64 | return attention_lstm__model 65 | -------------------------------------------------------------------------------- /DLM/Preprocess.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | import pandas as pd 4 | import numpy as np 5 | from numpy import concatenate 6 | from math import sqrt 7 | import pickle 8 | 9 | from sklearn.preprocessing import MinMaxScaler 10 | 11 | from minepy import MINE 12 | 13 | 14 | def micfliter(data,rate): 15 | 16 | """ 17 | MIC feture selection function 18 | Arguments: 19 | data: Pandas DataFrame of 20 | rate: Float in range(0,1) 21 | Return: 22 | List of to drop 23 | """ 24 | 25 | m = MINE() 26 | micmatrix = [] 27 | for colx in data.columns: 28 | micResult = [] 29 | for coly in data.columns: 30 | m.compute_score(np.array(data[coly]), np.array(data[colx])) 31 | micResult.append(m.mic()) 32 | micmatrix.append(micResult) 33 | 34 | micmatrix = pd.DataFrame(micmatrix,columns=data.columns) 35 | upper = micmatrix.where(np.triu(np.ones(micmatrix.shape), k=1).astype(np.bool)) 36 | to_drop = [column for column in upper.columns if any(upper[column]>rate)] 37 | 38 | return to_drop 39 | 40 | 41 | def Scaler(data): 42 | 43 | """ 44 | Scaler all feature to range(0,1) 45 | Arguments: 46 | data: Pandas DataFrame of data 47 | Return: 48 | scaler: scaler 49 | scaledDf:Pandas DataFrame of scaled data 50 | """ 51 | 52 | values = data.values 53 | values = values.astype('float32') 54 | scaler = MinMaxScaler(feature_range=(0,1)) 55 | scaled = scaler.fit_transform(values) 56 | scaledDf = pd.DataFrame(scaled,columns=data.columns) 57 | return scaler,scaledDf 58 | 59 | 60 | def series_to_supervised(data, n_in=1, n_out=1, dropnan=True): 61 | """ 62 | Frame a time series as a supervised learning dataset. 63 | Arguments: 64 | data: Sequence of observations as a list or NumPy array. 65 | n_in: Number of lag observations as input (X). 66 | n_out: Number of observations as output (y). 67 | dropnan: Boolean whether or not to drop rows with NaN values. 68 | Returns: 69 | Pandas DataFrame of series framed for supervised learning. 70 | """ 71 | 72 | n_vars = 1 if type(data) is list else data.shape[1] 73 | df = pd.DataFrame(data) 74 | cols, names = list(), list() 75 | # input sequence (t-n, ... t-1) 76 | for i in range(n_in, 0, -1): 77 | cols.append(df.shift(i)) 78 | names += [('var%d(t-%d)' % (j+1, i)) for j in range(n_vars)] 79 | # forecast sequence (t, t+1, ... t+n) 80 | for i in range(0, n_out): 81 | cols.append(df.shift(-i)) 82 | if i == 0: 83 | names += [('var%d(t)' % (j+1)) for j in range(n_vars)] 84 | else: 85 | names += [('var%d(t+%d)' % (j+1, i)) for j in range(n_vars)] 86 | # put it all together 87 | agg = pd.concat(cols, axis=1) 88 | agg.columns = names 89 | # drop rows with NaN values 90 | if dropnan: 91 | agg.dropna(inplace=True) 92 | 93 | agg.drop(agg.columns[-(df.shape[1]-1):],axis = 1,inplace=True) 94 | return agg 95 | 96 | 97 | 98 | if __name__ == '__main__': 99 | 100 | data = pd.read_csv(".\\dataset\\Macau2018.csv") 101 | data.drop(columns=["date","arrival mainland"],inplace=True) 102 | data.fillna(0,inplace=True) 103 | 104 | data_x = data[data.columns[1:]] 105 | droplist = micfliter(data_x,rate=0.9) 106 | reducedData = data.drop(droplist, axis=1) 107 | 108 | scaler,scaledDf = Scaler(reducedData) 109 | reframed = series_to_supervised(scaledDf,n_in=12) 110 | 111 | with open('.\\preprocess\\scaler.pk','wb') as f: 112 | pickle.dump(scaler, f) 113 | with open('.\\preprocess\\reframed.pk','wb') as a: 114 | pickle.dump(reframed, a) 115 | -------------------------------------------------------------------------------- /DLM/README.md: -------------------------------------------------------------------------------- 1 | # DLM 2 | --- 3 | 4 | | Field | Value | 5 | | --- | --- | 6 | | Title | DLM | 7 | | Type | Source Code | 8 | | Language | Python | 9 | | License | | 10 | | Status | Research Code | 11 | | Update Frequency | NO | 12 | | Date Published | 2019-01-31 | 13 | | Date Updated | 2019-01-31 | 14 | | Portal | https://github.com/tulip-lab/open-code | 15 | | URL | https://github.com/tulip-lab/open-code/tree/master/DLM| 16 | | Publisher |[TULIP Lab](http://www.tulip.org.au/) | 17 | | Point of Contact |[A/Prof. Gang Li](https://github.com/tuliplab) | 18 | 19 | This package (DLM) is the deep learning algorithm for tourism demand forecasting. Please be aware that: 20 | 21 | * The training of DLM needs extra efforts based on specific data set, and direct running of the provided code *DOES NOT* always generate the promised performance. 22 | * For the training of the model on the data set, please spend your own patient time and the code publisher will *NOT* provide assistance on this issue. 23 | 24 | --- 25 | ### Citations 26 | --- 27 | 28 | If you use it for a scientific publication, please include a reference to this paper. 29 | 30 | * Rob Law, Gang Li, Davis Fong, Xin Han (2019). [Tourism Demand Forecasting: A Deep Learning Approach](https://doi.org/10.1016/j.annals.2019.01.014). **Annals of Tourism Research**, Vol 75, March 2019, Page 410-423 31 | 32 | `BibTex` information: 33 | 34 | @article{LLFHDeep2019, 35 | title = {Tourism Demand Forecasting: A Deep Learning Approach}, 36 | volume = {75}, 37 | doi = {10.1016/j.annals.2019.01.014}, 38 | journal = {Annals of Tourism Research}, 39 | author = {Law, Rob and Li, Gang and Fong, Davis Ka Chio and Han, Xin}, 40 | month = March, 41 | year = {2019}, 42 | keywords = {Big data analytics, Deep Learning, Search query data,Tourism Demand Forecast}, 43 | pages = {410-423}, 44 | } 45 | 46 | The related dataset for above paper can be found at [TULIP Lab Open-Data](https://github.com/tulip-lab/open-data): 47 | 48 | * [`Macau2018`](https://github.com/tulip-lab/open-data/tree/master/Macau2018): Tourism Demand Forcasting Data for Macau from January 2011 to August 2018 49 | 50 | 51 | --- 52 | ### Requirements 53 | --- 54 | 55 | * Python 3.6 56 | * Keras 57 | * Tensorflow 58 | 59 | 60 | --- 61 | ### Preprocessing 62 | --- 63 | 64 | * Window-based input (window size is 12) 65 | 66 | 67 | --- 68 | ## Running 69 | --- 70 | 71 | ``` 72 | edit Setting.py % set paramaters 73 | python Preprocess.py % data preprocess 74 | python Eval.py % model evaluation 75 | 76 | ``` 77 | 78 | 79 | -------------------------------------------------------------------------------- /DLM/Setting.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | lstm_unit = [512,256,128,64,32,16] 4 | drop_rate = [0.2,0.3,0.5,0.7,0.8] 5 | dense_unit = [256,128,64,32,16,8] 6 | batch_size_num = [2,3,7,11,12,15] 7 | epochs = [300,500,700,1000,3000] -------------------------------------------------------------------------------- /DLM/preprocess/reframed.pk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulip-lab/open-code/afcc27a3cabf9b5658309b84a9940c8533a397ca/DLM/preprocess/reframed.pk -------------------------------------------------------------------------------- /DLM/preprocess/scaler.pk: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulip-lab/open-code/afcc27a3cabf9b5658309b84a9940c8533a397ca/DLM/preprocess/scaler.pk -------------------------------------------------------------------------------- /GANBLR/README.md: -------------------------------------------------------------------------------- 1 | # GANBLR 2 | --- 3 | 4 | | Field | Value | 5 | | --- | --- | 6 | | Title | GANBLR | 7 | | Type | Source Code | 8 | | Language | Python | 9 | | License | BSD license | 10 | | Status | Research Code | 11 | | Update Frequency | NO | 12 | | Date Published | 2022-04-30 | 13 | | Date Updated | 2022-04-30 | 14 | | Portal | https://github.com/tulip-lab/open-code | 15 | | URL | https://github.com/tulip-lab/open-code/tree/master/GANBLR| 16 | | Publisher |[TULIP Lab](http://www.tulip.org.au/) | 17 | | Point of Contact |[A/Prof. Gang Li](https://github.com/tuliplab) | 18 | 19 | 20 | GANBLR is a novel tabular data generation algorithm. It uses the higher order discriminative Bayesian Network and also the neural network to generate the synthetic tabular data. 21 | 22 | --- 23 | ### Citations 24 | --- 25 | 26 | If you use it for a scientific publication, please include a reference to this paper. 27 | 28 | * Yishuo Zhang, Nayyar Zaidi, Jiahui Zhou, and Gang Li, [GANBLR: A Tabular Data Generation Model](https://ieeexplore.ieee.org/abstract/document/9679177), IEEE, 2021. 29 | 30 | `BibTex` information: 31 | 32 | ```bibtex 33 | @inproceedings{zhang2021ganblr, 34 | title={GANBLR: A Tabular Data Generation Model}, 35 | author={Zhang, Yishuo and Zaidi, Nayyar A and Zhou, Jiahui and Li, Gang}, 36 | booktitle={2021 IEEE International Conference on Data Mining (ICDM)}, 37 | pages={181--190}, 38 | year={2021}, 39 | organization={IEEE} 40 | } 41 | ``` 42 | 43 | 44 | 45 | --- 46 | ### Requirements 47 | --- 48 | 49 | * Python 3 50 | * PGMPY 51 | * Pyitlib 52 | * Data must be discretized before adding to input 53 | --- 54 | ### License 55 | --- 56 | 57 | BSD license 58 | -------------------------------------------------------------------------------- /GP-DLM/DLM.py: -------------------------------------------------------------------------------- 1 | import configuration 2 | from keras.utils import np_utils 3 | from keras.layers import * 4 | from keras.models import * 5 | from keras.optimizers import Adam 6 | from keras.regularizers import l2,l1 7 | from keras.initializers import * 8 | 9 | 10 | def attention_3d_block_f(inputs): 11 | # a = Permute((2, 1))(inputs) 12 | a = Dense(input_dim+1, activation='relu', use_bias=True)(inputs) 13 | a = Activation('softmax')(a) 14 | # a_probs = Permute((2, 1), name='attention_vec')(a) 15 | output_attention_mul = multiply([inputs, a], name='attention_mul') 16 | return output_attention_mul 17 | 18 | 19 | def attention_3d_block_m(inputs): 20 | a = Permute((2, 1))(inputs) 21 | a = Dense(12, activation='relu', use_bias=True)(a) 22 | a = Activation('softmax')(a) 23 | a_probs = Permute((2, 1), name='attention_vec1')(a) 24 | output_attention_mul = multiply([inputs, a_probs], name='attention_mul1') 25 | return output_attention_mul 26 | # build RNN model with attention 27 | 28 | def dlm(train_x,train_y,test_x,test_y,dim1,dim2,dim3,dropout_1,batchsize,epoch): 29 | inputs2 = Input(shape=(12, dim1)) 30 | attention_mul1 = attention_3d_block_f(inputs2) 31 | # attention_mul2 = attention_3d_block_m(inputs2) 32 | lstm_out2 = LSTM(dim2, return_sequences=False, activation='relu', dropout=0.01, kernel_initializer=he_normal(), 33 | name='bilstm1')( 34 | attention_mul1) 35 | 36 | drop2 = Dropout(dropout_1)(lstm_out2) 37 | output1 = Dense(dim3, kernel_initializer=he_normal(), activation='relu')(drop2) 38 | output1 = Dense(1, kernel_initializer=he_normal())(output1) 39 | model2 = Model(inputs=inputs2, outputs=output1) 40 | model2.compile(loss='mape', optimizer='adam') 41 | #model2.summary() 42 | model2.fit(train_x,train_y, batch_size=batchsize, epochs=epoch, callbacks=cbks, verbose=1, 43 | validation_data=(test_x,test_y)) 44 | return model2 -------------------------------------------------------------------------------- /GP-DLM/Dynamic_time_warping_distance.py: -------------------------------------------------------------------------------- 1 | from sklearn.preprocessing import MinMaxScaler 2 | import pandas as pd 3 | import numpy as np 4 | from pandas import Series 5 | from pandas import DataFrame 6 | import statsmodels.api as sm 7 | from scipy.spatial.distance import euclidean 8 | from fastdtw import fastdtw 9 | 10 | 11 | #import HK and MO data 12 | data_hk = pd.read_csv("HK-2018.csv") 13 | data_mo = pd.read_csv("MO-2018.csv") 14 | 15 | 16 | series_hk = data_hk[['Date','Arrival']] 17 | series_hk.Date = pd.to_datetime(series_hk.Date,errors='coerce') 18 | series_hk = series_hk.set_index('Date') 19 | 20 | 21 | series_mo = data_mo[['Date','Arrival']] 22 | series_mo.Date = pd.to_datetime(series_mo.Date,errors='coerce') 23 | series_mo = series_mo.set_index('Date') 24 | 25 | #decompose the data into trend / seasonality / noise 26 | res_hk = sm.tsa.seasonal_decompose(series_hk) 27 | res_mo = sm.tsa.seasonal_decompose(series_mo) 28 | #scaling the data 29 | scaler = MinMaxScaler() 30 | trend_hk = res_hk.trend.dropna() 31 | trend_mo = res_mo.trend.dropna() 32 | 33 | sea_hk = res_hk.seasonal.dropna() 34 | sea_mo = res_mo.seasonal.dropna() 35 | 36 | trend_hk = np.array(trend_hk ).reshape(-1,1) 37 | trend_hk _nor = scaler.fit_transform(trend_hk ) 38 | trend_mo = np.array(trend_mo ).reshape(-1,1) 39 | trend_mo _nor = scaler.fit_transform(trend_mo ) 40 | 41 | sea_hk = np.array(sea_hk ).reshape(-1,1) 42 | sea_hk _nor = scaler.fit_transform(sea_hk ) 43 | 44 | sea_mo = np.array(sea_mo ).reshape(-1,1) 45 | sea_mo_nor = scaler.fit_transform(sea_mo ) 46 | 47 | distance1, path1 = fastdtw(trend_mo_nor.reshape(80,), trend_hk_nor.reshape(80,), dist=euclidean) 48 | print(distance1) 49 | distance2, path2 = fastdtw(sea_mo_nor, sea_hk_nor, dist=euclidean) 50 | print(distance1) 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /GP-DLM/README.md: -------------------------------------------------------------------------------- 1 | # `GP-DLM` 2 | --- 3 | 4 | | Field | Value | 5 | | --- | --- | 6 | | Title | GP-DLM | 7 | | Type | Source Code | 8 | | Language | Python | 9 | | License | | 10 | | Data Status | Research Code | 11 | | Update Frequency | NO | 12 | | Date Published | 2020-02-26 | 13 | | Date Updated | 2020-02-26 | 14 | | Portal | https://github.com/tulip-lab/open-code | 15 | | URL | https://github.com/tulip-lab/open-code/tree/master/GP-DLM| 16 | | Publisher |[TULIP Lab](http://www.tulip.org.au/) | 17 | | Point of Contact |[A/Prof. Gang Li](https://github.com/tuliplab) | 18 | 19 | This package (GP-DLM) is the group pooling deep learning algorithm for tourism demand forecasting. Please be aware that: 20 | 21 | * The pooling stage will need run the extra dynamic time warping clustering for generating the pooling group. 22 | * Pooling data is generated separately. 23 | * The training of DLM needs extra efforts based on specific data set, and direct running of the provided code *DOES NOT* always generate the promised performance. 24 | * For the training of the model on the data set, please spend your own patient time and the code publisher will *NOT* provide assistance on this issue. 25 | 26 | --- 27 | ### Citations 28 | --- 29 | 30 | If you use it for a scientific publication, please include a reference to this paper. 31 | 32 | * Yishuo Zhang, Gang Li, Birgit Muskat, Rob Law and Yating Yang(2020). [Group Pooling For Deep Tourism Demand Forecasting](https://doi.org/10.1016/j.annals.2020.102899). **Annals of Tourism Research**, Vol 82, May 2020 33 | 34 | 35 | `BibTex` information: 36 | 37 | @article{ZLMLY2020, 38 | title = {Group Pooling For Deep Tourism Demand Forecasting}, 39 | volume = {82}, 40 | doi = {10.1016/j.annals.2020.102899}, 41 | journal = {Annals of Tourism Research}, 42 | author = {Zhang, Yishuo and Li, Gang and Muskat, Birgit and Law, Rob and Yang, Yating}, 43 | month = May, 44 | year = {2020}, 45 | keywords = {tourism demand forecasting, AI-based methodology, group-pooling method, deep-learning model, tourism demand similarity, Asia Pacific travel patterns}, 46 | } 47 | 48 | The related dataset `HK-MO2018` for above paper can be found at [TULIP Lab Open-Data](https://github.com/tulip-lab/open-data): 49 | 50 | * [`HK-MO2018`](https://github.com/tulip-lab/open-data/tree/master/HK-MO2018) 51 | 52 | 53 | --- 54 | ### Requirements 55 | --- 56 | 57 | * Python 3.6 58 | * Keras 2.2 (2.3 won't work for the weights saving) 59 | * Tensorflow 60 | 61 | 62 | --- 63 | ### Run the coder 64 | --- 65 | 66 | * Setting up the pooling data by using Dynamic_time_warping.py and pooling.py 67 | * Feeding the pooled data into DLM by using DLM.py and configuration.py 68 | * Run the forecasting.py 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /GP-DLM/configuration.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import matplotlib.pyplot as plt 3 | import pandas as pd 4 | from pandas import datetime 5 | import math, time 6 | import itertools 7 | from sklearn import preprocessing 8 | import datetime 9 | from operator import itemgetter 10 | from sklearn.metrics import mean_squared_error 11 | from math import sqrt 12 | from keras.models import Sequential 13 | from keras.layers.core import Dense, Dropout, Activation 14 | from keras.layers.recurrent import LSTM 15 | from keras.models import load_model 16 | import keras 17 | import h5py 18 | import requests 19 | import os 20 | from keras.callbacks import LearningRateScheduler, TensorBoard , EarlyStopping, ModelCheckpoint, ReduceLROnPlateau 21 | 22 | input_dim = 256 23 | input_dim1 = 36 24 | input_dim2 = 48 25 | input_dim3 = 60 26 | lstm_1 = 512 27 | lstm_2 = 512 28 | dense1 = 256 29 | dense2 = 256 -------------------------------------------------------------------------------- /GP-DLM/forecasting.py: -------------------------------------------------------------------------------- 1 | import configuation 2 | import DLM 3 | import pooling 4 | import numpy as np 5 | import matplotlib.pyplot as plt 6 | import pandas as pd 7 | from pandas import datetime 8 | import math, time 9 | import itertools 10 | from sklearn import preprocessing 11 | import datetime 12 | from operator import itemgetter 13 | from sklearn.metrics import mean_squared_error 14 | from math import sqrt 15 | from keras.models import Sequential 16 | from keras.layers.core import Dense, Dropout, Activation 17 | from keras.layers.recurrent import LSTM 18 | from keras.models import load_model 19 | import keras 20 | import h5py 21 | import requests 22 | import os 23 | from keras.callbacks import LearningRateScheduler, TensorBoard , EarlyStopping, ModelCheckpoint, ReduceLROnPlateau 24 | 25 | 26 | def mape_vectorized_v2(a, b): 27 | mask = a != 0 28 | return (np.fabs(a - b)/a)[mask].mean() 29 | 30 | 31 | lstm_unit = [512,256,128,64,32] 32 | drop_1 = [0.2,0.3,0.5,0.7] 33 | dense_unit = [128,64,32] 34 | drop_2 = [0.2,0.3,0.5] 35 | batch_size_num = [7,12] 36 | 37 | grid_search_ = list(itertools.product(lstm_unit, drop_1, dense_unit, drop_2, batch_size_num)) 38 | 39 | history_x = [x for x in train_x] 40 | history_y = [y for y in train_y] 41 | history_x_a = np.array(history_x) 42 | history_y_a = np.array(history_y) 43 | predictions = [] 44 | mape_error = [] 45 | 46 | for x in grid_search_[0:2]: 47 | history_x = [x for x in train_x] 48 | history_y = [y for y in train_y] 49 | history_x_a = np.array(history_x) 50 | history_y_a = np.array(history_y) 51 | mape_error1 = [] 52 | predictions1 = [] 53 | for i in range(len(test_x)): 54 | # 预测 55 | model= dlm(history_x_a,history_y_a,test_x[i], test_y[i],x[0],x[1],x[2],x[3],x[4]) 56 | yhat = model.predict(test_x[i]) 57 | error = mape_vectorized_v2(test_y[i],yhat) 58 | mape_error1.append(error) 59 | predictions1.append(yhat) 60 | # 观测+ 61 | history_x_a = np.append(history_x_a,test_x[i],axis = 0) 62 | history_y_a = np.append(history_y_a,test_y[i],axis = 0) 63 | print(x,mape_error1) -------------------------------------------------------------------------------- /GP-DLM/pooling.py: -------------------------------------------------------------------------------- 1 | from datetime import datetime 2 | from numpy import nan 3 | from numpy import isnan 4 | import sklearn 5 | import sklearn.preprocessing 6 | import numpy as np 7 | import configuration 8 | 9 | # Import data from your own path 10 | dataset1 = read_csv('./data/HK-2018.csv') 11 | # manually specify column names 12 | dataset1.index.name = 'date' 13 | #dataset1 = dataset1[6:86] 14 | 15 | 16 | df_finalfeature = dataset1.drop(['date','arrival','seasonality','trend'], axis=1) 17 | df_finalfeature.replace(np.nan, 0, inplace=True) 18 | 19 | np.where(np.isnan(df_finalfeature.values)) 20 | 21 | scaler = sklearn.preprocessing.MinMaxScaler() 22 | df_finalfeature__nor = pd.DataFrame(scaler.fit_transform(df_finalfeature), columns=df_finalfeature.columns) 23 | df_finalfeature__nor.describe() 24 | 25 | df_df = pd.concat([df_finalfeature__nor,dataset1['arrival']/1000000],axis = 1) 26 | df_df = df_df[6:86] 27 | df_1 = df_df.as_matrix() # convert to numpy array 28 | data_1 = [] 29 | 30 | # create all possible sequences of length seq_len 31 | for index in range(len(df_1) - 13): 32 | data_1.append(df_1[index: index + 13]) 33 | 34 | 35 | 36 | # Import data from your own path 37 | dataset2 = read_csv('./data/MO-2018.csv') 38 | dataset2.index.name = 'date' 39 | df_finalfeature1 = dataset2.drop(['date','arrival','seasonality','trend'], axis=1) 40 | df_finalfeature1.replace(np.nan, 0, inplace=True) 41 | 42 | np.where(np.isnan(df_finalfeature1.values)) 43 | 44 | scaler = sklearn.preprocessing.MinMaxScaler() 45 | df_finalfeature__nor1 = pd.DataFrame(scaler.fit_transform(df_finalfeature1), columns=df_finalfeature1.columns) 46 | df_finalfeature__nor1.describe() 47 | 48 | df_df1 = pd.concat([df_finalfeature__nor1,dataset2['arrival']/1000000],axis = 1) 49 | df_df1 = df_df1[6:86] 50 | df_2 = df_df1.as_matrix() # convert to numpy array 51 | data_2 = [] 52 | 53 | # create all possible sequences of length seq_len 54 | for index in range(len(df_2) - 13): 55 | data_2.append(df_2[index: index + 13]) 56 | 57 | data_1 = np.array(data_1) 58 | y_1 = np.zeros((len(data_1), 1)) 59 | for i in range(0,len(y_1)): 60 | y_1[i]=data_1[i][12][256] 61 | 62 | 63 | x_1 = np.zeros((len(data_1),12,257)) 64 | for i in range(0,len(x_1)): 65 | x_1[i]=data_1[i][0:12] 66 | 67 | data_2 = np.array(data_2) 68 | y_2 = np.zeros((len(data_2), 1)) 69 | for i in range(0,len(y_2)): 70 | y_2[i]=data_2[i][12][256] 71 | 72 | 73 | x_2 = np.zeros((len(data_2),12,257)) 74 | for i in range(0,len(x_2)): 75 | x_2[i]=data_2[i][0:12] 76 | 77 | train_x11215 = x_1[0:36] 78 | train_y11215 = y_1[0:36] 79 | train_x21215 = x_2[0:36] 80 | train_y21215 = y_2[0:36] 81 | 82 | test_x12016 = x_1[36:48] 83 | test_y12016 = y_1[36:48] 84 | test_x12017 = x_1[48:60] 85 | test_y12017 = y_1[48:60] 86 | test_x22016 = x_2[36:48] 87 | test_y22016 = y_2[36:48] 88 | test_x22017 = x_2[48:60] 89 | test_y22017 = y_2[48:60] 90 | 91 | train_x11217 = x_1[0:60] 92 | train_y11217 = y_1[0:60] 93 | train_x21217 = x_2[0:60] 94 | train_y21217 = y_2[0:60] 95 | 96 | train_1215 = np.concatenate((train_x11215, train_x21215), axis=0) 97 | train_1215y = np.concatenate((train_y11215, train_y21215), axis=0) 98 | shuffle = np.random.permutation(train_1215.shape[0]) 99 | 100 | train_1215_new=np.take(train_1215,shuffle,axis=0) 101 | train_1215_newy=np.take(train_1215y,shuffle,axis=0) -------------------------------------------------------------------------------- /IK-AHC/.gitignore: -------------------------------------------------------------------------------- 1 | # Windows default autosave extension 2 | *.asv 3 | 4 | # OSX / *nix default autosave extension 5 | *.m~ 6 | 7 | # Compiled MEX binaries (all platforms) 8 | *.mex* 9 | 10 | # Packaged app and toolbox files 11 | *.mlappinstall 12 | *.mltbx 13 | 14 | # Generated helpsearch folders 15 | helpsearch*/ 16 | 17 | # Simulink code generation folders 18 | slprj/ 19 | sccprj/ 20 | 21 | # Matlab code generation folders 22 | codegen/ 23 | 24 | # Simulink autosave extension 25 | *.autosave 26 | 27 | # Simulink cache files 28 | *.slxc 29 | 30 | # Octave session info 31 | octave-workspace 32 | 33 | # dataset 34 | data/ 35 | -------------------------------------------------------------------------------- /IK-AHC/LICENSE: -------------------------------------------------------------------------------- 1 | BSD 3-Clause License 2 | 3 | Copyright (c) 2022, Xin Han 4 | All rights reserved. 5 | 6 | Redistribution and use in source and binary forms, with or without 7 | modification, are permitted provided that the following conditions are met: 8 | 9 | 1. Redistributions of source code must retain the above copyright notice, this 10 | list of conditions and the following disclaimer. 11 | 12 | 2. Redistributions in binary form must reproduce the above copyright notice, 13 | this list of conditions and the following disclaimer in the documentation 14 | and/or other materials provided with the distribution. 15 | 16 | 3. Neither the name of the copyright holder nor the names of its 17 | contributors may be used to endorse or promote products derived from 18 | this software without specific prior written permission. 19 | 20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | -------------------------------------------------------------------------------- /IK-AHC/README.md: -------------------------------------------------------------------------------- 1 | # IK-AHC 2 | --- 3 | 4 | | Field | Value | 5 | | --- | --- | 6 | | Title | IK-AHC | 7 | | Type | Source Code | 8 | | Language | Matlab | 9 | | License | BSD license | 10 | | Status | Research Code | 11 | | Update Frequency | NO | 12 | | Date Published | 2022-04-16 | 13 | | Date Updated | 2022-04-16 | 14 | | Portal | https://github.com/tulip-lab/open-code | 15 | | URL | https://github.com/tulip-lab/open-code/tree/master/IK-AHC| 16 | | Publisher |[TULIP Lab](http://www.tulip.org.au/) | 17 | | Point of Contact |[A/Prof. Gang Li](https://github.com/tuliplab) | 18 | 19 | 20 | IK-AHC is a novel hierarchical clustering algorithm. It uses a data-dependent kernel called Isolation Kernel to measure the the similarity between clusters. 21 | 22 | --- 23 | ### Citations 24 | --- 25 | 26 | If you use it for a scientific publication, please include a reference to this paper. 27 | 28 | * Xin Han, Ye Zhu, Kai Ming Ting, and Gang Li, [The Impact of Isolation Kernel on Agglomerative Hierarchical Clustering Algorithms](https://arxiv.org/pdf/2010.05473.pdf), arXiv e-prints, 2020. 29 | 30 | `BibTex` information: 31 | 32 | ```bibtex 33 | @article{HZTLThe2020, 34 | author = {Han, Xin and Zhu, Ye and Ting, Kai Ming and Li, Gang}, 35 | title = {The Impact of Isolation Kernel on Agglomerative Hierarchical Clustering Algorithms}, 36 | publisher = {arXiv}, 37 | year = {2020}, 38 | url = {https://arxiv.org/abs/2010.05473}, 39 | copyright = {arXiv.org perpetual, non-exclusive license} 40 | } 41 | ``` 42 | 43 | 46 | 47 | --- 48 | ### Requirements 49 | --- 50 | 51 | * Matlab R2021a 52 | 53 | --- 54 | ### Setup 55 | --- 56 | 57 | Add the preject permanently to the Matlab path: 58 | 59 | ```matlab 60 | run setup.m 61 | ``` 62 | 63 | --- 64 | ### Run Evaluation 65 | --- 66 | 67 | Run test on all real data set: 68 | 69 | ```matlab 70 | run eva/eva_khc.m 71 | ``` 72 | 73 | --- 74 | ### Notes 75 | --- 76 | 77 | - Most of the program running time is used to calculate dendrogram purity. 78 | - You'll need firstly run the setup script before run the evaluation script. 79 | 80 | --- 81 | ### License 82 | --- 83 | 84 | BSD license 85 | -------------------------------------------------------------------------------- /IK-AHC/eva/eva_khc.m: -------------------------------------------------------------------------------- 1 | % Copyright 2022 Xin Han. All rights reserved. 2 | % Use of this source code is governed by a BSD-style 3 | % license that can be found in the LICENSE file. 4 | 5 | clear 6 | clc 7 | close all 8 | 9 | % Dataset 10 | dataset = []; 11 | dataname = {}; 12 | mat = dir('Data/real/*.mat'); 13 | 14 | for q = 1:length(mat) 15 | data = load(strcat('Data/real/', mat(q).name)); 16 | dataname{end + 1} = mat(q).name(1:end - 4); 17 | dataset = [dataset data]; 18 | end 19 | 20 | len_data = length(dataset); 21 | 22 | % Model paramters 23 | lk_func = 'single'; % 'single', 'average', 'complete', 'weighted', 24 | 25 | % Distance paramters 26 | class_num = 2:1:30; 27 | 28 | % File set 29 | fileID_f1sore = fopen('exp_out/khc/ik/f1_score.csv', 'w'); 30 | fileID_purity = fopen('exp_out/khc/ik/purity.csv', 'w'); 31 | formatSpec = '%s, %s, %s, %2.2f\n'; 32 | 33 | for i = 1:len_data 34 | data_n = length(dataset(i).class); 35 | 36 | % Isolation kernel paramters 37 | psi_set = 2:1:int32(data_n / 2); 38 | 39 | % Normalization 40 | data = dataset(i).data; 41 | data = (data - min(data)) .* ((max(data) - min(data)).^ - 1); 42 | data(isnan(data)) = 0.5; 43 | 44 | %% evaluate isolation kernel 45 | f1_score = 0; 46 | purity = 0; 47 | 48 | for psi = psi_set 49 | 50 | htoc_ik_Z = tahc_cluster(1-IsolationKernel(data, psi, 200, false), lk_func); 51 | f1_score = max(f1_score, f1_tree(htoc_ik_Z, dataset(i).class, class_num)); 52 | purity = max(purity, DenPurity(htoc_ik_Z, dataset(i).class)); 53 | 54 | end 55 | 56 | C_f1_score = {cell2mat(dataname(i)), lk_func, 'Isolationkernel', f1_score}; 57 | fprintf(fileID_f1sore, formatSpec, C_f1_score{:}); 58 | 59 | C_purity = {cell2mat(dataname(i)), lk_func 'Isolationkernel', purity}; 60 | fprintf(fileID_purity, formatSpec, C_purity{:}); 61 | 62 | end 63 | 64 | fclose(fileID_f1sore); 65 | fclose(fileID_purity); 66 | -------------------------------------------------------------------------------- /IK-AHC/eva/utils/format_result_table.py: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Xin Han. All rights reserved. 2 | # Use of this source code is governed by a BSD-style 3 | # license that can be found in the LICENSE file. 4 | 5 | import numpy as np 6 | import sys 7 | 8 | 9 | def load_result_file(fn): 10 | """ 11 | Result file format: 12 | algorithm dataset dendrogram purity 13 | Args: 14 | fn: filename 15 | Returns: dictionary: alg -> dataset -> (mean(dp),std(dp) 16 | """ 17 | alg2dataset2score = {} 18 | alg2mean = {} 19 | with open(fn, 'r') as fin: 20 | for line in fin: 21 | try: 22 | splt = line.strip().split("\t") 23 | dataset, alg, dp = splt[:3] 24 | if alg not in alg2dataset2score: 25 | alg2dataset2score[alg] = {} 26 | alg2mean[alg] = {} 27 | if dataset not in alg2dataset2score[alg]: 28 | alg2dataset2score[alg][dataset] = [] 29 | alg2dataset2score[alg][dataset].append(float(dp)) 30 | except: 31 | pass 32 | for alg in alg2dataset2score: 33 | mean_score = np.mean([alg2dataset2score[alg][data] 34 | for data in alg2dataset2score[alg]]) 35 | alg2mean[alg]["_mean_score"] = mean_score 36 | 37 | for alg in alg2dataset2score: 38 | for dataset in alg2dataset2score[alg]: 39 | mean = np.mean(alg2dataset2score[alg][dataset]) 40 | std = np.std(alg2dataset2score[alg][dataset]) 41 | alg2dataset2score[alg][dataset] = (mean, std) 42 | return (alg2dataset2score, alg2mean) 43 | 44 | 45 | def escape_latex(s): 46 | s = s.replace("_", "\\_") 47 | return s 48 | 49 | 50 | def latex_table(alg_score): 51 | table_string = """\\begin{table}\n\\centering\n\\caption{some caption}\n\\begin{tabular}""" 52 | # num_ds = max([len(alg2dataset2score[x]) for x in alg2dataset2score]) 53 | alg2dataset2score = alg_score[0] 54 | alg2mean = alg_score[1] 55 | num_al = len(alg2dataset2score) 56 | formatting = "{c" + "c" * num_al + "}" 57 | table_string += format(formatting) 58 | table_string += "\n\\toprule\n" 59 | alg_names = alg2dataset2score.keys() 60 | 61 | ds_names = list( 62 | set([name for x in alg2dataset2score for name in alg2dataset2score[x]])) 63 | table_string += "\\bf Dataset & \\bf " + \ 64 | " & \\bf ".join(escape_latex(x) for x in alg_names) 65 | table_string += " \\\\ \midrule\n" 66 | ds_names = sorted(ds_names) 67 | socre_mean = [alg2mean[alg]["_mean_score"] for alg in alg_names] 68 | for ds in ds_names: 69 | scores = ["%.2f $\\pm$ %.2f" % (alg2dataset2score[alg][ds][0], alg2dataset2score[alg][ds][1]) 70 | if ds in alg2dataset2score[alg] else "-" for alg in alg_names] 71 | table_string += "%s & %s \\\\\n" % (ds, " & ".join(scores)) 72 | table_string += "\midrule\n" 73 | table_string += "bf Mean & " + \ 74 | " & ".join("{:.2f}".format(x) for x in socre_mean) 75 | table_string += " \\\\ \\bottomrule\n\\end{tabular}\n\\end{table}" 76 | return table_string 77 | 78 | 79 | if __name__ == "__main__": 80 | print(latex_table(load_result_file(sys.argv[1]))) -------------------------------------------------------------------------------- /IK-AHC/eva/utils/plot_parameter.py: -------------------------------------------------------------------------------- 1 | # Copyright 2022 Xin Han. All rights reserved. 2 | # Use of this source code is governed by a BSD-style 3 | # license that can be found in the LICENSE file. 4 | 5 | import os 6 | 7 | import matplotlib.pyplot as plt 8 | import numpy as np 9 | import pandas as pd 10 | 11 | 12 | # setting 13 | dataname = "thyroid" 14 | y_label = 'F1 Score' # 'F1 Score', 'purity' 15 | score_type = 'f1_score' # 'f1_score', 'Dendrogram Purity' 16 | period = 10 17 | 18 | file_path = './exp_out/khc/repeat_para/'+score_type+'.csv' 19 | save_path = './exp_out/khc/repeat_para/'+score_type 20 | 21 | 22 | os.makedirs(save_path, exist_ok=True) 23 | 24 | data = pd.read_csv(file_path, header=None, names=[ 25 | 'data', 'alg', 'kernel', 'psi', 'value']) 26 | 27 | subdata = data[data["data"] == dataname] 28 | dfm = subdata.groupby(['alg', 'psi']).agg([np.mean, np.std]) 29 | 30 | plt.style.use(['science', 'ieee', 'retro']) 31 | stack_dfm = dfm["value"].unstack(level=0) 32 | 33 | x = stack_dfm[::period].index.tolist() 34 | pha_y = stack_dfm[::period]['mean'][' PHA'].tolist() 35 | pha_yerr = stack_dfm[::period]['std'][' PHA'].tolist() 36 | 37 | average_y = stack_dfm[::period]['mean'][' average'].tolist() 38 | average_yerr = stack_dfm[::period]['std'][' average'].tolist() 39 | 40 | single_y = stack_dfm[::period]['mean'][' single'].tolist() 41 | single_yerr = stack_dfm[::period]['std'][' single'].tolist() 42 | 43 | 44 | data_1 = { 45 | 'label': 'PHA', 46 | 'x': x, 47 | 'y': pha_y, 48 | 'yerr': pha_yerr, 49 | 'fmt': ':', 50 | 'color': '#e770a2', 51 | } 52 | 53 | data_2 = { 54 | 'label': 'Average', 55 | 'x': x, 56 | 'y': average_y, 57 | 'yerr': average_yerr, 58 | 'fmt': '-.', 59 | 'color': '#f79a1e', 60 | } 61 | 62 | data_3 = { 63 | 'label': 'Single', 64 | 'x': x, 65 | 'y': single_y, 66 | 'yerr': single_yerr, 67 | 'fmt': '--', 68 | 'color': '#4165c0', 69 | } 70 | 71 | 72 | for data in [data_3, data_1, data_2]: 73 | plt.ylim([0.0, 1.0]) 74 | plt.errorbar(**data, alpha=.75, capsize=3, capthick=1) 75 | data = { 76 | 'x': data['x'], 77 | 'y1': [y - e for y, e in zip(data['y'], data['yerr'])], 78 | 'y2': [y + e for y, e in zip(data['y'], data['yerr'])], 79 | 'facecolor': data['color']} 80 | plt.fill_between(**data, alpha=.15) 81 | 82 | plt.xlabel('$\psi$') 83 | plt.ylabel(ylabel=y_label) 84 | plt.legend(loc='lower right') 85 | plt.tight_layout() 86 | plt.savefig(os.path.join(save_path, dataname+'_bar.pdf')) 87 | -------------------------------------------------------------------------------- /IK-AHC/exp_out/khc/ik/.gitkeep: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /IK-AHC/setup.m: -------------------------------------------------------------------------------- 1 | function eva_setup = setup() 2 | root = fileparts(mfilename('fullpath')); 3 | addpath(genpath(fullfile(root, 'eva'))); 4 | addpath(genpath(fullfile(root, 'src'))); 5 | end -------------------------------------------------------------------------------- /IK-AHC/src/kernel/IsolationKernel.m: -------------------------------------------------------------------------------- 1 | function m_sim = IsolationKernel(data, psi, t, sq) 2 | 3 | m_dist = pdist2(data, data); 4 | n = size(m_dist, 1); 5 | m_sim = zeros(size(m_dist)); 6 | 7 | parfor i = 1:t % parfor MAY NOT work with acceleration by single GPU 8 | subIndex = datasample(1:n, psi, 'Replace', false); 9 | [~, centerIdx] = min(m_dist(subIndex, :)); 10 | m_sim = m_sim + (centerIdx' == centerIdx); 11 | end 12 | 13 | m_sim = m_sim / t; 14 | 15 | if sq == false 16 | m = tril(true(size(m_sim)), -1); 17 | m_sim = m_sim(m)'; 18 | end 19 | 20 | end 21 | -------------------------------------------------------------------------------- /IK-AHC/src/metric/DenPurity.m: -------------------------------------------------------------------------------- 1 | function [Purity] = DenPurity(L, class) 2 | %class: true label 3 | %% building parent index matrix 4 | %%%% row is instance index collunm is parent index 5 | n = size(L, 1) + 1; % number of instances 6 | Tclass = [1:length(class)]'; 7 | 8 | L(:, end + 1) = (size(L, 1) + (1:size(L, 1))) + 1; 9 | 10 | ParentMatrix = zeros(n, 2 * n); 11 | 12 | for i = 1:size(L, 1) 13 | CurrentIndex = []; 14 | 15 | if L(i, 1) > n 16 | ind = find(ParentMatrix(:, L(i, 1)) == 1)'; 17 | CurrentIndex = [CurrentIndex ind]; 18 | else 19 | CurrentIndex = [CurrentIndex L(i, 1)]; 20 | end 21 | 22 | if L(i, 2) > n 23 | ind = find(ParentMatrix(:, L(i, 2)) == 1)'; 24 | CurrentIndex = [CurrentIndex ind]; 25 | else 26 | CurrentIndex = [CurrentIndex L(i, 2)]; 27 | end 28 | 29 | ParentMatrix(CurrentIndex, L(i, 4)) = 1; 30 | end 31 | 32 | ParentMatrix(:, [1:n 2 * n]) = []; 33 | 34 | C = unique(class); 35 | T = unique(Tclass); 36 | Pure = 0; 37 | S = 0; 38 | tc_index = zeros(length(C), 2 * n - 1); 39 | subtree_sum = zeros(1, n); 40 | 41 | for ci = 1:length(C) 42 | 43 | for ti = 1:n 44 | subtree = find(Tclass == T(ti)); 45 | subtree_sum(ti) = length(subtree); 46 | tc = find(class(subtree) == C(ci)); 47 | tc_index(ci, ti) = length(tc) / length(subtree); 48 | end 49 | 50 | for ti = n + 1:2 * n - 1 51 | Tinstances = find(ParentMatrix(:, ti - n) == 1); 52 | p = 0; 53 | 54 | for i = 1:length(Tinstances) 55 | p = p + tc_index(ci, Tinstances(i)) * subtree_sum(Tinstances(i)); 56 | end 57 | 58 | tc_index(ci, ti) = p / sum(subtree_sum(Tinstances)); 59 | end 60 | 61 | end 62 | 63 | for Ci = 1:length(C) 64 | CurrentInstance = find(class == C(Ci)); 65 | 66 | for i = 1:length(CurrentInstance) 67 | 68 | for j = i + 1:length(CurrentInstance) 69 | tc1 = Tclass(CurrentInstance(i)); 70 | tc2 = Tclass(CurrentInstance(j)); 71 | 72 | if tc1 == tc2 % The lca is the pskc cluster 73 | Pure = Pure + tc_index(Ci, tc1); 74 | 75 | else 76 | ShareParent = find(ParentMatrix(tc1, :) .* ParentMatrix(tc2, :) == 1); % find the nearest parent 77 | 78 | Pure = Pure + tc_index(Ci, ShareParent(1) + n); 79 | end 80 | 81 | S = S + 1; 82 | end 83 | 84 | end 85 | 86 | end 87 | 88 | Purity = Pure / S; 89 | end 90 | -------------------------------------------------------------------------------- /IK-AHC/src/metric/ExpDenPurity.m: -------------------------------------------------------------------------------- 1 | function [Purity] = ExpDenPurity(L, class) 2 | 3 | %% building parent index matrix 4 | %%%% row is instance index collunm is parent index 5 | n = size(L, 1) + 1; % number of instances 6 | 7 | L(:, end + 1) = (size(L, 1) + (1:size(L, 1))) + 1; 8 | 9 | ParentMatrix = zeros(n, 2 * n); 10 | 11 | for i = 1:size(L, 1) 12 | CurrentIndex = []; 13 | 14 | if L(i, 1) > n 15 | ind = find(ParentMatrix(:, L(i, 1)) == 1)'; 16 | CurrentIndex = [CurrentIndex ind]; 17 | else 18 | CurrentIndex = [CurrentIndex L(i, 1)]; 19 | end 20 | 21 | if L(i, 2) > n 22 | ind = find(ParentMatrix(:, L(i, 2)) == 1)'; 23 | CurrentIndex = [CurrentIndex ind]; 24 | else 25 | CurrentIndex = [CurrentIndex L(i, 2)]; 26 | end 27 | 28 | ParentMatrix(CurrentIndex, L(i, 4)) = 1; 29 | end 30 | 31 | ParentMatrix(:, [1:n 2 * n]) = []; 32 | 33 | %% scanning 34 | 35 | C = unique(class); 36 | Pure = 0; 37 | S = 0; 38 | 39 | for Ci = 1:length(C) 40 | CurrentInstance = find(class == C(Ci)); 41 | n = floor(0.5 * length(CurrentInstance)); 42 | 43 | for sam = 1:n 44 | sample_i = randsample(CurrentInstance, 1, 'false'); 45 | sample_j = randsample(CurrentInstance, 1, 'false'); 46 | ShareParent = find(ParentMatrix(sample_i, :) .* ParentMatrix(sample_j, :) == 1); % find the nearest parent 47 | instances = find(ParentMatrix(:, ShareParent(1)) == 1); % instances sharing the same parent 48 | Pure = Pure + sum(class(instances) == C(Ci)) / length(instances); % purity score 49 | S = S + 1; 50 | end 51 | 52 | end 53 | 54 | Purity = Pure / S; % average purity score 55 | end 56 | -------------------------------------------------------------------------------- /IK-AHC/src/metric/Fmeasure.m: -------------------------------------------------------------------------------- 1 | function [f1, recall, precision] = Fmeasure(ground_truth, class) 2 | % Written by: Ye Zhu 3 | % Altered by: Xiaoyu Qin 4 | 5 | matrix = zeros(max(ground_truth), max(class)); 6 | noise = zeros(max(ground_truth), 1); 7 | s = size(class, 1); 8 | 9 | for i = 1:s % test each example 10 | 11 | if class(i) > 0 12 | matrix(ground_truth(i), class(i)) = matrix(ground_truth(i), class(i)) + 1; 13 | else 14 | noise(ground_truth(i)) = noise(ground_truth(i)) + 1; 15 | end 16 | 17 | end 18 | 19 | indF = zeros(max(ground_truth), 1); 20 | 21 | if size(matrix, 2) ~= 0 22 | [f1, recall, precision, match] = fmean(matrix, noise); 23 | [posc, ~] = find(match == 1); 24 | 25 | for i = 1:size(posc, 1) 26 | indF(posc(i)) = f1(i); 27 | end 28 | 29 | f1 = sum(indF) / max(ground_truth); 30 | recall = sum(recall) / max(ground_truth); 31 | precision = sum(precision) / max(ground_truth); 32 | else 33 | f1 = 0; 34 | recall = 0; 35 | precision = 0; 36 | end 37 | 38 | end 39 | 40 | function [f1, recall, precision, match] = fmean(matrix, noise) 41 | 42 | % first round 43 | recall = calc_recall(matrix); 44 | precision = calc_precision (matrix); 45 | f1 = 2 * precision .* recall ./ (precision + recall + 0.0000001); 46 | 47 | [match, ~] = hungarian(-f1); 48 | matrix = [matrix noise]; 49 | [r, c] = size(matrix); 50 | [rr, cc] = size(match); 51 | match1 = [match; zeros(r - rr, cc)]; 52 | match1 = [match1 zeros(r, c - cc)]; 53 | 54 | % re-calculate 55 | recall = calc_recall(matrix); 56 | precision = calc_precision (matrix); 57 | f1 = 2 * precision .* recall ./ (precision + recall + 0.0000001); 58 | 59 | f1 = f1(match1 == 1); 60 | precision = precision(match1 == 1); 61 | recall = recall(match1 == 1); 62 | 63 | end 64 | 65 | function [m_recall] = calc_recall (matrix) 66 | m_recall = matrix; 67 | sumrow = sum(matrix, 2); 68 | 69 | if size(matrix, 2) == 1 70 | sumrow = matrix; 71 | end 72 | 73 | for j = 1:size(matrix, 1) 74 | m_recall(j, :) = m_recall(j, :) / (sumrow(j) + 0.0000001); % calculate the total positive examples 75 | end 76 | 77 | end 78 | 79 | function [m_precision] = calc_precision (matrix) 80 | m_precision = matrix; 81 | sumcol = sum(matrix); 82 | 83 | if size(matrix, 1) == 1 84 | sumcol = matrix; 85 | end 86 | 87 | for j = 1:size(matrix, 2) 88 | m_precision(:, j) = m_precision(:, j) / (sumcol(j) + 0.0000001); % calculate the total positive examples 89 | end 90 | 91 | end 92 | -------------------------------------------------------------------------------- /IK-AHC/src/metric/f1_tree.m: -------------------------------------------------------------------------------- 1 | function f1_score = f1_tree(Z, class, class_num) 2 | 3 | f1_score = 0; 4 | 5 | for cl = class_num 6 | idx = cluster(Z, 'maxclust', cl); 7 | f1 = Fmeasure(class, idx); 8 | f1_score = max(f1_score, f1); 9 | end 10 | 11 | end 12 | -------------------------------------------------------------------------------- /IK-AHC/src/models/TAHC/tahc_cluster.m: -------------------------------------------------------------------------------- 1 | function Z = tahc_cluster(dist, method) 2 | 3 | % ---INPUT--- 4 | % dist: The distance between the rows of X, form of pdist function 5 | % method: linkage function of traditional AHC. 6 | 7 | % ---OUTPUT--- 8 | % Z: hierarchical cluster tree which is represented as a matrix with size (numPts-1 X 3) 9 | 10 | [numPts, numPts2] = size(dist); % numPts is the number of points 11 | if (numPts == numPts2) 12 | error('ErrorFormOfDistanceMatrix: distance should be a vector form like output of pdist function! '); 13 | end 14 | 15 | Z = linkage(dist, method); 16 | 17 | end -------------------------------------------------------------------------------- /PREDICTIVITY/README.md: -------------------------------------------------------------------------------- 1 | # PREDICTIVITY 2 | --- 3 | 4 | | Field | Value | 5 | | --- | --- | 6 | | Title | PREDICTIVITY | 7 | | Type | Source Code | 8 | | Language | Python | 9 | | License | | 10 | | Status | Research Code | 11 | | Update Frequency | NO | 12 | | Date Published | 2021-04-27 | 13 | | Date Updated | 2021-08-29 | 14 | | Portal | https://github.com/tulip-lab/open-code | 15 | | URL | https://github.com/tulip-lab/open-code/tree/master/PREDICTIVITY| 16 | | Publisher |[TULIP Lab](http://www.tulip.org.au/) | 17 | | Point of Contact |[A/Prof. Gang Li](https://github.com/tuliplab) | 18 | 19 | This package (PREDICTIVITY) is the algorithm for calculating tourism demand data predictivity. Please be aware that: 20 | 21 | * The entropy calculation is depending on the distance value r. 22 | * For very small distance value r, the predictivity will be unavailable. 23 | 24 | --- 25 | ### Citations 26 | --- 27 | 28 | If you use it for a scientific publication, please include a reference to this paper. 29 | 30 | * Yishuo Zhang, Gang Li, Birgit Muskat, HuyQuan Vu, Rob Law (2021). [Predictivity of tourism demand data](https://doi.org/10.1016/j.annals.2021.103234). **Annals of Tourism Research** 31 | 32 | 33 | `BibTex` information: 34 | 35 | @article{ZLML2021, 36 | title = {Predictivity of tourism demand data}, 37 | journal = {Annals of Tourism Research}, 38 | volume = {89}, 39 | pages = {103234}, 40 | year = {2021}, 41 | issn = {0160-7383}, 42 | doi = {https://doi.org/10.1016/j.annals.2021.103234}, 43 | url = {https://www.sciencedirect.com/science/article/pii/S0160738321001122}, 44 | author = {Yishuo Zhang and Gang Li and Birgit Muskat and Huy Quan Vu and Rob Law}, 45 | keywords = {Data characteristics, Entropy, Predictivity, Tourism demand forecasting} 46 | } 47 | 48 | --- 49 | ### Requirements 50 | --- 51 | 52 | * Python 3.6 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /PREDICTIVITY/predictivity_ssa.py: -------------------------------------------------------------------------------- 1 | !pip install pyts 2 | #prepare to install the SSA library 3 | from mySSA import mySSA 4 | #https://github.com/aj-cloete/pssa 5 | # load and read the HK data 6 | series_sa = pd.read_csv('hongkong_new.csv', parse_dates=True, index_col='Date') 7 | ssa = mySSA(series_sa['arrival']) 8 | #setting SSA parameter 9 | suspected_seasonality = 12 10 | ssa.embed(embedding_dimension=30, suspected_frequency=suspected_seasonality, verbose=True 11 | #plot the HK data 12 | ssa.ts.plot(title='Original Time Series'); # This is the original series for comparison 13 | streams5 = [i for i in range(5)] 14 | #create the reconstruction 15 | reconstructed2 = ssa.view_reconstruction(*[ssa.Xs[i] for i in streams5], names=streams5, return_df=True) 16 | # plot the reconstruction and calculate the entropy 17 | X_sa = reconstructed2.values.reshape(-1,) 18 | msentropy_sa = ent.multiscale_entropy(X_sa,2,0.25*np.std(X_sa),30) 19 | fig, ax1 = plt.subplots(figsize=(6, 4)) 20 | sns.lineplot(data=np.array(msentropy_or)[0:12], color="teal",label="Origin series entropy") 21 | ax1.set_ylabel('Entropy') 22 | ax1.set_xlabel('Scale level(months)') 23 | sns.lineplot(data=np.array(msentropy_sa)[0:12], color="r",label="SSA series entropy") 24 | plt.xticks([0,2,4,6,8,10],["1","3","5","7","9","11"]) 25 | plt.legend(loc='upper left') 26 | 27 | # calculate the predictivity and plot 28 | phi_max_or=[] 29 | phi_max_sa=[] 30 | for i in range(len(msentropy_gt)): 31 | phi_max_or.append(phi_max(msentropy_or[i],280)) 32 | phi_max_sa.append(phi_max(msentropy_sa[i],280)) 33 | 34 | fig, ax1 = plt.subplots(figsize=(6, 4)) 35 | sns.lineplot(data=np.array(phi_max_or)[0:12], color="teal",label="Origin series Phi_max") 36 | ax1.set_ylabel('Phi_max') 37 | ax1.set_xlabel('Scale level(months)') 38 | sns.lineplot(data=np.array(phi_max_sa)[0:12], color="r",label="SSA series Phi_max") 39 | plt.xticks([0,2,4,6,8,10],["1","3","5","7","9","11"]) 40 | plt.legend(loc='upper right') 41 | 42 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TULIP Lab Open Code 2 | 3 | --- 4 | - Open code for research purpose, you are free to use, change and distribute this package with the `README.md` information unchanged. 5 | - Point of Contact: [A/Prof. Gang Li](https://github.com/tuliplab) 6 | 7 | Prepared by [TULIP Lab](http://www.tulip.org.au), Australia 8 | 9 | - 2022 maintainers: [Xin Han](https://github.com/xhan97) 10 | - 2021 maintainers: [Chris Zhang](https://github.com/chriszhangpodo) 11 | - 2020 maintainers: [Chris Zhang](https://github.com/chriszhangpodo) 12 | - 2019 maintainers: [Xin Han](https://github.com/xhan97) 13 | 14 | --- 15 | 16 | ## Content 17 | 18 | * [`Adam`](Adam): Adaptive-maximum imputation for neighborhood-based collaborative filtering, proposed in [Lazy Collaborative Filtering for Datasets with Missing Values](http://dx.doi.org/10.1109/TSMCB.2012.2231411), **IEEE Transactions on Systems, Man, and Cybernetics, Part B: Cybernetics**, 2013, 43(6): 1822-1834 19 | * [`CTR`](CTR): Contrast Targeted Positive and Negative Association Rule Mining (CTR) algorithm, proposed in [Identifying Changes And Trends In Hong Kong Outbound Tourism](http://dx.doi.org/10.1016/j.tourman.2010.09.011), **Tourism Management**, 2011, Vol 32(5), Pages 1106-1114 20 | * [`DLM`](DLM): A Deep Learning Package for Tourism Demand Forecasting, proposed in [Tourism Demand Forecasting: A Deep Learning Approach](https://doi.org/10.1016/j.annals.2019.01.014), **Annals of Tourism Research**, Vol 75, March 2019, Page 410-423 21 | * [`GP-DLM`](GP-DLM): A Deep Learning Package for Group Pooling Tourism Demand Forecasting, proposed in [Group Pooling For Deep Tourism Demand Forecasting](https://doi.org/10.1016/j.annals.2020.102899). **Annals of Tourism Research**, Vol 82, May 2020 22 | * [`PREDICTIVITY`](PREDICTIVITY): Univariate Time Series Predictivity, proposed in [Predictivity of tourism demand data](https://doi.org/10.1016/j.annals.2021.103234). **Annals of Tourism Research**, May 2021 23 | * [`RFM`](RFM): Tools for handling fuzzy measures, calculating Shapley value and Interaction index, Choquet Integrals, as well as fitting fuzzy measures to empirical data, as introduced in [A Choquet Integral Toolbox and Its Application in Customer Preference Analysis](http://books.google.com.au/books?id=nYpqAAAAQBAJ&pg=PA247&lpg=PA247&dq=A+Choquet+Integral+Toolbox+and+Its+Application+in+Customer+Preference+Analysis&source=bl&ots=wK84Bsn2D9&sig=sr_xiaV1bdYkObsKy2EdrK9yH4M&hl=en&sa=X&ei=6obWUumMMsjdkgXN9IDYDA&ved=0CD4Q6AEwAg#v=onepage&q=A%20Choquet%20Integral%20Toolbox%20and%20Its%20Application%20in%20Customer%20Preference%20Analysis&f=false), **Data Mining Application with R**, Elsevier, 2013 24 | * [`STL-DADLM`](STL-DADLM): A Deep Learning Package for STL Decomposition Tourism Demand Forecasting, proposed in [Tourism Demand Forecasting: A Decomposed Deep Learning Approach](https://doi.org/10.1177/0047287520919522 ). **Journal of Travel Research**, 2020 25 | * [`IK-AHC`](IK-AHC): The Impact of Isolation Kernel on Agglomerative Hierarchical Clustering Algorithms in [The Impact of Isolation Kernel on Agglomerative Hierarchical Clustering Algorithms](https://arxiv.org/pdf/2010.05473.pdf), arXiv e-prints, 2020. 26 | * [`GANBLR`](GANBLR): The novel tabular data generation algorithm in [GANBLR: A Tabular Data Generation Model](https://ieeexplore.ieee.org/abstract/document/9679177), ICDM 2021 IEEE, 2021. 27 | * [`StreaKHC`](StreaKHC): Streaming Hierarchical Clustering based on Point-set Kernel. Streaming Hierarchical Clustering based on Point-set Kernel. **In The 28th ACM SIGKDD Conference on Knowledge Discovery & Data Mining (KDD '22)**. 2022. 28 | 29 | --- -------------------------------------------------------------------------------- /RFM/Rfmtool.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulip-lab/open-code/afcc27a3cabf9b5658309b84a9940c8533a397ca/RFM/Rfmtool.tar.gz -------------------------------------------------------------------------------- /RFM/Rfmtool.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulip-lab/open-code/afcc27a3cabf9b5658309b84a9940c8533a397ca/RFM/Rfmtool.zip -------------------------------------------------------------------------------- /RFM/packages/DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: Rfmtool 2 | Version: 1.0 3 | Date: 2012-08-01 4 | Title: Rfmtool 5 | Author: Huy Quan Vu, Gleb Beliakov and Gang Li. 6 | Maintainer: Quan Vu 7 | Depends: R (>= 2.9.2) 8 | Suggests: 9 | Description: Programming library of fuzzy measure which provides various tools for handling fuzzy measures, calculating Shapley value and Interaction index, Cho-quet integrals, as well as fitting fuzzy measures to empirical data. 10 | License: LGPL-2.1 11 | URL: http://www.tulip.org.au/resources/rfmtool 12 | BugReports: to gleb.beliakov@deakin.edu.au or quan@tulip.com.au 13 | Packaged: 2012-11-07 09:54:55 UTC; default 14 | Built: R 3.1.2; x86_64-w64-mingw32; 2015-01-16 11:45:31 UTC; windows 15 | Archs: i386, x64 16 | -------------------------------------------------------------------------------- /RFM/packages/INDEX: -------------------------------------------------------------------------------- 1 | Rfmtool Rfmtool package 2 | fm Rfmtool package 3 | fm.Choquet Choquet function 4 | fm.ChoquetMob ChoquetMob function 5 | fm.Interaction Interaction Index computation function 6 | fm.Mobius Mobius transform function 7 | fm.Shapley Shapley value computation function 8 | fm.Zeta Zeta transform function 9 | fm.fitting Fuzzy Measure Fitting function 10 | fm.test A Test function 11 | -------------------------------------------------------------------------------- /RFM/packages/MD5: -------------------------------------------------------------------------------- 1 | 4cc48cda5310ad557e1485189a472527 *DESCRIPTION 2 | aaeb3024d32e107f884788a17ef8523a *INDEX 3 | fc5fa4129cd39bd5de16764dbc9bf400 *Meta/Rd.rds 4 | 1b243d8f0d75df619276bef81f35da73 *Meta/data.rds 5 | e4b63d96f617145db8a7f1c43db40917 *Meta/hsearch.rds 6 | eed0d6b24db277b4e6d45e23bf21234a *Meta/links.rds 7 | 320fe46cb24107c31bfffe79ff551a5b *Meta/nsInfo.rds 8 | 9f28e1233e10efb891e9179ff7bf35a2 *Meta/package.rds 9 | 604b71ac3b6edb5165d6f811998c23d8 *NAMESPACE 10 | ebf0fc819595d631b8bf280c4b049940 *R/Rfmtool 11 | 178820ad295b48d9a1aebbf34d292b88 *R/Rfmtool.rdb 12 | 41bfb85b96fab41bba3449617461918e *R/Rfmtool.rdx 13 | 4516e68b4241a632de2ec9b2cd06af3e *data/Original/Singapore-Hotel2011.csv 14 | d6bbee0fe2411efe450ede42128667bd *data/Preprocessed/Business-Asia.txt 15 | c5c8466625604a95cf232a5f10dd7aac *data/Preprocessed/Business-Europe.txt 16 | eb7b0b5d0e326c382d700c60215cbbb5 *data/Preprocessed/Business-NothAmerica.txt 17 | a71bac07cb044d138ad97d739440f43f *data/Preprocessed/Business-Oceania.txt 18 | fed67adb2669ff72b9b8043de124ea69 *data/Preprocessed/Business.txt 19 | a98cc1ac4c90f9ef7bfc361d8a5eef08 *data/Preprocessed/Couple-Asia.txt 20 | 1ea03ee12ffd04c6f5b3d6978e8f24b1 *data/Preprocessed/Couple-Europe.txt 21 | 0348bcd4e2bd8c86d2fc28583b37753d *data/Preprocessed/Couple-NothAmerica.txt 22 | 3f2c5abf41aabf26dc13bc42ef138edd *data/Preprocessed/Couple-Oceania.txt 23 | 777817ec934b711a63914e8f68207ac8 *data/Preprocessed/Couple.txt 24 | b9ccd75a7bc3a38abd948e1f6256c365 *data/Preprocessed/Family-America.txt 25 | c729a45ad01ccf5b7601bc3cf5963f42 *data/Preprocessed/Family-Asia.txt 26 | c9a8a18ffa0dc104fbf38fabeaa413ec *data/Preprocessed/Family-Europe.txt 27 | 75f45562288042a23f4a6894340d1fd3 *data/Preprocessed/Family-Oceania.txt 28 | 1069da114e38841c1d0411743ad32d23 *data/Preprocessed/Family.txt 29 | daaccd5daaafeead4476c76efa8cbcfd *example/AMEvaluation.r 30 | 9b9aafb7bfc6653f15348a72e4dc72a2 *example/ChoquetEvaluation.r 31 | bd655e0841d149e34d06009a5cf46286 *example/DataAnalysisRoutine.r 32 | 756c6e258e0c75c96d6f3c52d01383ac *example/PreferenceAnalysisExample.r 33 | a67493e1df32423e2602ef2eca1008fb *example/WAMEvaluation.r 34 | ee4069497d766a73475cef0cdba58b70 *example/data.txt 35 | 666725ff0961aa0b790822d539147a92 *help/AnIndex 36 | 159b1f6a64797555bcfd2cb5ee19108f *help/Rfmtool.rdb 37 | 1bf5b81c3fc2353ba4a328e01d961c79 *help/Rfmtool.rdx 38 | 84acc076a55d17304225cde53688c02c *help/aliases.rds 39 | 82284a904a749ffe48271ec17d81aedc *help/paths.rds 40 | f9e58f728666148cc78d0f77b7749cea *html/00Index.html 41 | 444535b9cb76ddff1bab1e1865a3fb14 *html/R.css 42 | eb8a35bac481e61c7060ca4e70b5a801 *libs/i386/Rfmtool.dll 43 | bde7cc19dc9da3dba03027c388283e99 *libs/x64/Rfmtool.dll 44 | -------------------------------------------------------------------------------- /RFM/packages/Meta/Rd.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulip-lab/open-code/afcc27a3cabf9b5658309b84a9940c8533a397ca/RFM/packages/Meta/Rd.rds -------------------------------------------------------------------------------- /RFM/packages/Meta/data.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulip-lab/open-code/afcc27a3cabf9b5658309b84a9940c8533a397ca/RFM/packages/Meta/data.rds -------------------------------------------------------------------------------- /RFM/packages/Meta/hsearch.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulip-lab/open-code/afcc27a3cabf9b5658309b84a9940c8533a397ca/RFM/packages/Meta/hsearch.rds -------------------------------------------------------------------------------- /RFM/packages/Meta/links.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulip-lab/open-code/afcc27a3cabf9b5658309b84a9940c8533a397ca/RFM/packages/Meta/links.rds -------------------------------------------------------------------------------- /RFM/packages/Meta/nsInfo.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulip-lab/open-code/afcc27a3cabf9b5658309b84a9940c8533a397ca/RFM/packages/Meta/nsInfo.rds -------------------------------------------------------------------------------- /RFM/packages/Meta/package.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulip-lab/open-code/afcc27a3cabf9b5658309b84a9940c8533a397ca/RFM/packages/Meta/package.rds -------------------------------------------------------------------------------- /RFM/packages/NAMESPACE: -------------------------------------------------------------------------------- 1 | useDynLib(Rfmtool) 2 | export(fm) 3 | export(fm.fitting) 4 | export(fm.Choquet) 5 | export(fm.ChoquetMob) 6 | export(fm.Mobius) 7 | export(fm.Zeta) 8 | export(fm.Shapley) 9 | export(fm.Interaction) 10 | export(fm.test) 11 | -------------------------------------------------------------------------------- /RFM/packages/R/Rfmtool: -------------------------------------------------------------------------------- 1 | # File share/R/nspackloader.R 2 | # Part of the R package, http://www.R-project.org 3 | # 4 | # Copyright (C) 1995-2012 The R Core Team 5 | # 6 | # This program is free software; you can redistribute it and/or modify 7 | # it under the terms of the GNU General Public License as published by 8 | # the Free Software Foundation; either version 2 of the License, or 9 | # (at your option) any later version. 10 | # 11 | # This program is distributed in the hope that it will be useful, 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | # GNU General Public License for more details. 15 | # 16 | # A copy of the GNU General Public License is available at 17 | # http://www.r-project.org/Licenses/ 18 | 19 | local({ 20 | info <- loadingNamespaceInfo() 21 | pkg <- info$pkgname 22 | ns <- .getNamespace(as.name(pkg)) 23 | if (is.null(ns)) 24 | stop("cannot find namespace environment for ", pkg, domain = NA); 25 | dbbase <- file.path(info$libname, pkg, "R", pkg) 26 | lazyLoad(dbbase, ns, filter = function(n) n != ".__NAMESPACE__.") 27 | }) 28 | -------------------------------------------------------------------------------- /RFM/packages/R/Rfmtool.rdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulip-lab/open-code/afcc27a3cabf9b5658309b84a9940c8533a397ca/RFM/packages/R/Rfmtool.rdb -------------------------------------------------------------------------------- /RFM/packages/R/Rfmtool.rdx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulip-lab/open-code/afcc27a3cabf9b5658309b84a9940c8533a397ca/RFM/packages/R/Rfmtool.rdx -------------------------------------------------------------------------------- /RFM/packages/data/Preprocessed/Family-America.txt: -------------------------------------------------------------------------------- 1 | 1 1 1 1 1 1 1 2 | 0.6 0.8 1 1 1 1 0.8 3 | 0.6 1 1 1 1 1 0.8 4 | 0.8 0.8 1 1 1 1 1 5 | 0.4 1 0.6 0.6 1 0.4 0.8 6 | 0.8 1 0.8 0.8 0.8 0.6 0.8 7 | 1 1 1 1 1 1 1 8 | 1 1 1 1 1 1 1 9 | 1 1 1 1 1 1 1 10 | 0.8 1 1 0.8 1 1 0.8 11 | 0.6 0.6 0.8 0.6 1 1 0.8 12 | 0.6 0.8 0.4 0.4 0.2 0.4 0.2 13 | 0.6 0.8 0.8 0.8 0.8 0.6 0.8 14 | 0.4 0.6 0.2 0.4 0.8 0.2 0.4 15 | 1 1 1 1 1 1 1 16 | 0.6 1 0.8 0.6 0.8 0.8 0.6 17 | 0.6 1 1 1 1 1 1 18 | 0.6 0.8 0.6 0.8 1 1 0.8 19 | 0.6 0.8 0.8 0.8 1 0.8 0.8 20 | 0.6 0.2 1 0.6 1 1 0.6 21 | 0.8 1 0.6 0.8 0.6 1 0.8 22 | 0.6 0.8 0.8 0.8 0.8 0.8 0.8 23 | 1 1 1 1 1 1 1 24 | 0.4 0.6 0.4 0.4 0.6 0.6 0.4 25 | 0.8 0.8 1 1 1 1 1 26 | 0.8 0.8 1 1 1 1 1 27 | 0.2 1 0.4 0.8 0.8 0.2 0.4 28 | 1 1 1 1 1 1 1 29 | 1 1 1 1 1 1 1 30 | 0.8 1 1 1 1 1 1 31 | 1 1 1 1 1 1 1 32 | 0.6 0.2 0.2 0.2 0.6 0.6 0.2 33 | 0.6 1 0.6 0.6 0.6 0.4 0.6 34 | 0.4 0.4 0.6 0.6 0.4 0.6 0.6 35 | 1 1 1 1 1 1 0.8 36 | 1 1 1 1 1 1 1 37 | 1 1 1 1 1 1 1 38 | 0.8 0.8 1 1 1 1 1 39 | 0.8 0.8 0.8 0.8 0.8 0.8 0.8 40 | 1 1 1 1 1 0.8 1 41 | 1 1 1 1 1 1 1 42 | 0.8 1 1 1 1 1 1 43 | 1 1 0.8 1 1 1 1 44 | 1 1 0.6 0.8 0.8 0.8 0.8 45 | 0.8 0.8 1 0.8 0.8 0.8 0.8 46 | 0.4 1 0.6 0.4 0.4 1 0.4 47 | 1 1 1 1 1 1 1 48 | 1 1 1 1 1 1 1 49 | 0.4 1 0.8 0.6 1 0.2 0.6 50 | 1 1 1 1 1 1 1 51 | 0.8 0.8 0.8 0.8 1 0.4 0.6 52 | 0.6 1 0.4 0.6 0.6 1 0.6 53 | 1 1 1 1 1 1 1 54 | 1 1 1 0.8 1 1 1 55 | 1 0.8 1 1 1 1 1 56 | 1 1 0.8 0.8 1 1 1 57 | 0.8 0.8 0.8 0.8 0.8 0.8 0.8 58 | 0.8 1 0.8 0.8 0.8 0.8 0.8 59 | 1 0.8 1 1 1 1 1 60 | 0.8 1 0.6 1 1 0.8 1 61 | 0.8 1 1 0.8 0.8 0.8 1 62 | 0.6 0.6 1 1 1 0.8 0.8 63 | 0.8 0.8 1 0.8 0.8 0.8 0.8 64 | 0.8 1 0.6 0.6 0.8 0.8 0.8 65 | 0.6 0.8 1 1 1 1 0.8 66 | 1 1 1 1 0.8 1 0.8 67 | 0.6 0.8 0.8 0.6 0.8 1 0.8 68 | 1 1 1 1 1 0.8 1 69 | 1 1 1 1 1 0.8 1 70 | 0.8 1 0.8 0.6 0.6 1 0.8 71 | 0.8 0.6 0.8 0.6 0.6 0.8 0.6 72 | 0.6 0.6 0.8 0.6 0.8 0.8 0.6 73 | 0.6 0.8 0.8 0.8 1 1 0.8 74 | 1 1 1 1 1 1 1 75 | 0.8 1 1 1 1 1 1 76 | 0.6 1 0.8 0.6 0.6 0.6 0.6 77 | 0.8 1 0.8 0.8 0.8 1 1 78 | 0.6 0.8 0.6 0.4 0.8 0.6 0.6 79 | 1 0.8 1 0.8 1 1 1 80 | 0.8 0.8 1 0.8 1 1 0.8 81 | 1 1 0.6 0.8 1 1 1 82 | 0.6 0.8 0.6 0.8 0.6 0.6 0.8 83 | 0.6 1 0.6 0.6 0.6 1 0.8 84 | 0.8 1 0.8 0.8 0.8 1 0.8 85 | 0.8 0.8 0.8 0.8 0.8 0.8 0.8 86 | 1 1 1 0.6 1 1 1 87 | 1 1 1 0.8 1 0.6 0.8 88 | 1 1 1 1 1 1 1 89 | 0.4 1 0.8 1 1 0.6 0.6 90 | 0.8 0.8 0.8 1 1 1 1 91 | 0.6 0.6 0.8 0.8 0.8 0.6 0.6 92 | 1 0.8 1 1 1 0.8 0.8 93 | 0.8 1 1 0.8 0.8 0.8 0.8 94 | 0.2 1 0.6 0.2 0.6 0.6 0.2 95 | 0.8 0.8 1 1 1 1 1 96 | 1 1 1 0.8 1 0.8 0.8 97 | 0.6 1 0.6 0.2 0.2 0.6 0.4 98 | 0.8 1 1 1 1 1 1 99 | 0.6 0.8 0.8 0.8 0.8 1 0.8 100 | 1 0.8 1 1 1 1 1 101 | 0.8 0.6 1 1 0.8 1 0.8 102 | 0.8 1 0.8 0.8 0.8 0.8 0.8 103 | 1 1 0.8 0.8 0.8 1 0.8 104 | 1 1 1 1 1 0.8 1 105 | 1 0.8 1 0.8 1 0.8 1 106 | 0.8 1 1 1 1 0.8 1 107 | 0.4 0.8 0.2 0.8 0.8 0.8 0.6 108 | 1 1 0.8 0.8 1 1 1 109 | 0.8 1 1 1 1 1 1 110 | 0.8 0.8 0.8 0.8 0.8 1 1 111 | 1 1 1 1 1 0.6 0.8 112 | 0.8 0.8 1 1 1 1 1 113 | 0.8 1 0.8 0.8 0.8 1 1 114 | 0.8 0.6 1 0.8 0.8 1 0.8 115 | 1 1 1 1 0.8 1 1 116 | 1 1 1 1 1 1 1 117 | 1 1 1 1 1 1 1 118 | 0.8 0.8 1 1 1 1 1 119 | 1 1 1 0.8 1 0.8 0.8 120 | 0.8 1 1 0.8 1 0.8 0.8 121 | 0.6 0.8 0.4 0.4 0.4 0.4 0.4 122 | 0.8 1 1 1 1 1 1 123 | 1 0.8 1 1 1 1 1 124 | 1 0.8 0.8 0.8 0.8 1 0.8 125 | 1 1 1 1 1 1 1 126 | 1 0.8 1 1 1 1 1 127 | 0.8 1 1 1 1 1 1 128 | 0.8 1 0.8 1 1 1 1 129 | 0.6 0.8 0.8 0.6 0.8 0.6 0.6 130 | 0.2 0.8 0.4 0.4 0.6 0.2 0.4 131 | 0.2 0.6 0.6 0.4 0.8 0.8 0.6 132 | -------------------------------------------------------------------------------- /RFM/packages/example/AMEvaluation.r: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulip-lab/open-code/afcc27a3cabf9b5658309b84a9940c8533a397ca/RFM/packages/example/AMEvaluation.r -------------------------------------------------------------------------------- /RFM/packages/example/ChoquetEvaluation.r: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulip-lab/open-code/afcc27a3cabf9b5658309b84a9940c8533a397ca/RFM/packages/example/ChoquetEvaluation.r -------------------------------------------------------------------------------- /RFM/packages/example/DataAnalysisRoutine.r: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulip-lab/open-code/afcc27a3cabf9b5658309b84a9940c8533a397ca/RFM/packages/example/DataAnalysisRoutine.r -------------------------------------------------------------------------------- /RFM/packages/example/PreferenceAnalysisExample.r: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulip-lab/open-code/afcc27a3cabf9b5658309b84a9940c8533a397ca/RFM/packages/example/PreferenceAnalysisExample.r -------------------------------------------------------------------------------- /RFM/packages/example/WAMEvaluation.r: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulip-lab/open-code/afcc27a3cabf9b5658309b84a9940c8533a397ca/RFM/packages/example/WAMEvaluation.r -------------------------------------------------------------------------------- /RFM/packages/example/data.txt: -------------------------------------------------------------------------------- 1 | 0.6 0.9 0.5 0.8 2 | 0.8 0.3 0.4 0.3 3 | 0.2 0.6 0.3 0.4 4 | 0.7 1 0.5 0.8 5 | 0.3 0.6 0.8 0.7 6 | 0.5 0.4 0.3 0.5 7 | 0.8 0.9 0.7 0.9 8 | 0.3 0.8 0.9 0.6 9 | 0.6 0.8 0.4 0.5 10 | 0.3 0.6 0.2 0.2 -------------------------------------------------------------------------------- /RFM/packages/help/AnIndex: -------------------------------------------------------------------------------- 1 | fm fm 2 | fm.Choquet fm.Choquet 3 | fm.ChoquetMob fm.ChoquetMob 4 | fm.fitting fm.fitting 5 | fm.Interaction fm.Interaction 6 | fm.Mobius fm.Mobius 7 | fm.Shapley fm.Shapley 8 | fm.test fm.test 9 | fm.Zeta fm.Zeta 10 | Rfmtool Rfmtool 11 | -------------------------------------------------------------------------------- /RFM/packages/help/Rfmtool.rdb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulip-lab/open-code/afcc27a3cabf9b5658309b84a9940c8533a397ca/RFM/packages/help/Rfmtool.rdb -------------------------------------------------------------------------------- /RFM/packages/help/Rfmtool.rdx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulip-lab/open-code/afcc27a3cabf9b5658309b84a9940c8533a397ca/RFM/packages/help/Rfmtool.rdx -------------------------------------------------------------------------------- /RFM/packages/help/aliases.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulip-lab/open-code/afcc27a3cabf9b5658309b84a9940c8533a397ca/RFM/packages/help/aliases.rds -------------------------------------------------------------------------------- /RFM/packages/help/paths.rds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulip-lab/open-code/afcc27a3cabf9b5658309b84a9940c8533a397ca/RFM/packages/help/paths.rds -------------------------------------------------------------------------------- /RFM/packages/html/00Index.html: -------------------------------------------------------------------------------- 1 | 2 | R: Rfmtool 3 | 4 | 5 | 6 |

Rfmtool 7 | 8 |

9 |
10 |
11 | [Up] 12 | [Top] 13 |

Documentation for package ‘Rfmtool’ version 1.0

14 | 15 | 17 | 18 |

Help Pages

19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 |
fmRfmtool package
fm.ChoquetChoquet function
fm.ChoquetMobChoquetMob function
fm.fittingFuzzy Measure Fitting function
fm.InteractionInteraction Index computation function
fm.MobiusMobius transform function
fm.ShapleyShapley value computation function
fm.testA Test function
fm.ZetaZeta transform function
RfmtoolRfmtool package
43 | 44 | -------------------------------------------------------------------------------- /RFM/packages/html/R.css: -------------------------------------------------------------------------------- 1 | BODY{ background: white; 2 | color: black } 3 | 4 | A:link{ background: white; 5 | color: blue } 6 | A:visited{ background: white; 7 | color: rgb(50%, 0%, 50%) } 8 | 9 | H1{ background: white; 10 | color: rgb(55%, 55%, 55%); 11 | font-family: monospace; 12 | font-size: x-large; 13 | text-align: center } 14 | 15 | H2{ background: white; 16 | color: rgb(40%, 40%, 40%); 17 | font-family: monospace; 18 | font-size: large; 19 | text-align: center } 20 | 21 | H3{ background: white; 22 | color: rgb(40%, 40%, 40%); 23 | font-family: monospace; 24 | font-size: large } 25 | 26 | H4{ background: white; 27 | color: rgb(40%, 40%, 40%); 28 | font-family: monospace; 29 | font-style: italic; 30 | font-size: large } 31 | 32 | H5{ background: white; 33 | color: rgb(40%, 40%, 40%); 34 | font-family: monospace } 35 | 36 | H6{ background: white; 37 | color: rgb(40%, 40%, 40%); 38 | font-family: monospace; 39 | font-style: italic } 40 | 41 | IMG.toplogo{ vertical-align: middle } 42 | 43 | IMG.arrow{ width: 30px; 44 | height: 30px; 45 | border: 0 } 46 | 47 | span.acronym{font-size: small} 48 | span.env{font-family: monospace} 49 | span.file{font-family: monospace} 50 | span.option{font-family: monospace} 51 | span.pkg{font-weight: bold} 52 | span.samp{font-family: monospace} 53 | 54 | div.vignettes a:hover { 55 | background: rgb(85%, 85%, 85%); 56 | } 57 | 58 | -------------------------------------------------------------------------------- /RFM/packages/libs/i386/Rfmtool.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulip-lab/open-code/afcc27a3cabf9b5658309b84a9940c8533a397ca/RFM/packages/libs/i386/Rfmtool.dll -------------------------------------------------------------------------------- /RFM/packages/libs/x64/Rfmtool.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulip-lab/open-code/afcc27a3cabf9b5658309b84a9940c8533a397ca/RFM/packages/libs/x64/Rfmtool.dll -------------------------------------------------------------------------------- /RFM/sources/DESCRIPTION: -------------------------------------------------------------------------------- 1 | Package: Rfmtool 2 | Version: 1.0 3 | Date: 2012-08-01 4 | Title: Rfmtool 5 | Author: Huy Quan Vu, Gleb Beliakov and Gang Li. 6 | Maintainer: Quan Vu 7 | Depends: R (>= 2.9.2) 8 | Suggests: 9 | Description: Programming library of fuzzy measure which provides various tools for handling fuzzy measures, calculating Shapley value and Interaction index, Cho-quet integrals, as well as fitting fuzzy measures to empirical data. 10 | License: LGPL-2.1 11 | URL: http://www.tulip.org.au/resources/rfmtool 12 | BugReports: to gleb.beliakov@deakin.edu.au or quan@tulip.com.au 13 | Packaged: 2012-11-07 09:54:55 UTC; default 14 | -------------------------------------------------------------------------------- /RFM/sources/NAMESPACE: -------------------------------------------------------------------------------- 1 | useDynLib(Rfmtool) 2 | export(fm) 3 | export(fm.fitting) 4 | export(fm.Choquet) 5 | export(fm.ChoquetMob) 6 | export(fm.Mobius) 7 | export(fm.Zeta) 8 | export(fm.Shapley) 9 | export(fm.Interaction) 10 | export(fm.test) 11 | -------------------------------------------------------------------------------- /RFM/sources/R/Rfmtool.r: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulip-lab/open-code/afcc27a3cabf9b5658309b84a9940c8533a397ca/RFM/sources/R/Rfmtool.r -------------------------------------------------------------------------------- /RFM/sources/inst/data/Preprocessed/Family-America.txt: -------------------------------------------------------------------------------- 1 | 1 1 1 1 1 1 1 2 | 0.6 0.8 1 1 1 1 0.8 3 | 0.6 1 1 1 1 1 0.8 4 | 0.8 0.8 1 1 1 1 1 5 | 0.4 1 0.6 0.6 1 0.4 0.8 6 | 0.8 1 0.8 0.8 0.8 0.6 0.8 7 | 1 1 1 1 1 1 1 8 | 1 1 1 1 1 1 1 9 | 1 1 1 1 1 1 1 10 | 0.8 1 1 0.8 1 1 0.8 11 | 0.6 0.6 0.8 0.6 1 1 0.8 12 | 0.6 0.8 0.4 0.4 0.2 0.4 0.2 13 | 0.6 0.8 0.8 0.8 0.8 0.6 0.8 14 | 0.4 0.6 0.2 0.4 0.8 0.2 0.4 15 | 1 1 1 1 1 1 1 16 | 0.6 1 0.8 0.6 0.8 0.8 0.6 17 | 0.6 1 1 1 1 1 1 18 | 0.6 0.8 0.6 0.8 1 1 0.8 19 | 0.6 0.8 0.8 0.8 1 0.8 0.8 20 | 0.6 0.2 1 0.6 1 1 0.6 21 | 0.8 1 0.6 0.8 0.6 1 0.8 22 | 0.6 0.8 0.8 0.8 0.8 0.8 0.8 23 | 1 1 1 1 1 1 1 24 | 0.4 0.6 0.4 0.4 0.6 0.6 0.4 25 | 0.8 0.8 1 1 1 1 1 26 | 0.8 0.8 1 1 1 1 1 27 | 0.2 1 0.4 0.8 0.8 0.2 0.4 28 | 1 1 1 1 1 1 1 29 | 1 1 1 1 1 1 1 30 | 0.8 1 1 1 1 1 1 31 | 1 1 1 1 1 1 1 32 | 0.6 0.2 0.2 0.2 0.6 0.6 0.2 33 | 0.6 1 0.6 0.6 0.6 0.4 0.6 34 | 0.4 0.4 0.6 0.6 0.4 0.6 0.6 35 | 1 1 1 1 1 1 0.8 36 | 1 1 1 1 1 1 1 37 | 1 1 1 1 1 1 1 38 | 0.8 0.8 1 1 1 1 1 39 | 0.8 0.8 0.8 0.8 0.8 0.8 0.8 40 | 1 1 1 1 1 0.8 1 41 | 1 1 1 1 1 1 1 42 | 0.8 1 1 1 1 1 1 43 | 1 1 0.8 1 1 1 1 44 | 1 1 0.6 0.8 0.8 0.8 0.8 45 | 0.8 0.8 1 0.8 0.8 0.8 0.8 46 | 0.4 1 0.6 0.4 0.4 1 0.4 47 | 1 1 1 1 1 1 1 48 | 1 1 1 1 1 1 1 49 | 0.4 1 0.8 0.6 1 0.2 0.6 50 | 1 1 1 1 1 1 1 51 | 0.8 0.8 0.8 0.8 1 0.4 0.6 52 | 0.6 1 0.4 0.6 0.6 1 0.6 53 | 1 1 1 1 1 1 1 54 | 1 1 1 0.8 1 1 1 55 | 1 0.8 1 1 1 1 1 56 | 1 1 0.8 0.8 1 1 1 57 | 0.8 0.8 0.8 0.8 0.8 0.8 0.8 58 | 0.8 1 0.8 0.8 0.8 0.8 0.8 59 | 1 0.8 1 1 1 1 1 60 | 0.8 1 0.6 1 1 0.8 1 61 | 0.8 1 1 0.8 0.8 0.8 1 62 | 0.6 0.6 1 1 1 0.8 0.8 63 | 0.8 0.8 1 0.8 0.8 0.8 0.8 64 | 0.8 1 0.6 0.6 0.8 0.8 0.8 65 | 0.6 0.8 1 1 1 1 0.8 66 | 1 1 1 1 0.8 1 0.8 67 | 0.6 0.8 0.8 0.6 0.8 1 0.8 68 | 1 1 1 1 1 0.8 1 69 | 1 1 1 1 1 0.8 1 70 | 0.8 1 0.8 0.6 0.6 1 0.8 71 | 0.8 0.6 0.8 0.6 0.6 0.8 0.6 72 | 0.6 0.6 0.8 0.6 0.8 0.8 0.6 73 | 0.6 0.8 0.8 0.8 1 1 0.8 74 | 1 1 1 1 1 1 1 75 | 0.8 1 1 1 1 1 1 76 | 0.6 1 0.8 0.6 0.6 0.6 0.6 77 | 0.8 1 0.8 0.8 0.8 1 1 78 | 0.6 0.8 0.6 0.4 0.8 0.6 0.6 79 | 1 0.8 1 0.8 1 1 1 80 | 0.8 0.8 1 0.8 1 1 0.8 81 | 1 1 0.6 0.8 1 1 1 82 | 0.6 0.8 0.6 0.8 0.6 0.6 0.8 83 | 0.6 1 0.6 0.6 0.6 1 0.8 84 | 0.8 1 0.8 0.8 0.8 1 0.8 85 | 0.8 0.8 0.8 0.8 0.8 0.8 0.8 86 | 1 1 1 0.6 1 1 1 87 | 1 1 1 0.8 1 0.6 0.8 88 | 1 1 1 1 1 1 1 89 | 0.4 1 0.8 1 1 0.6 0.6 90 | 0.8 0.8 0.8 1 1 1 1 91 | 0.6 0.6 0.8 0.8 0.8 0.6 0.6 92 | 1 0.8 1 1 1 0.8 0.8 93 | 0.8 1 1 0.8 0.8 0.8 0.8 94 | 0.2 1 0.6 0.2 0.6 0.6 0.2 95 | 0.8 0.8 1 1 1 1 1 96 | 1 1 1 0.8 1 0.8 0.8 97 | 0.6 1 0.6 0.2 0.2 0.6 0.4 98 | 0.8 1 1 1 1 1 1 99 | 0.6 0.8 0.8 0.8 0.8 1 0.8 100 | 1 0.8 1 1 1 1 1 101 | 0.8 0.6 1 1 0.8 1 0.8 102 | 0.8 1 0.8 0.8 0.8 0.8 0.8 103 | 1 1 0.8 0.8 0.8 1 0.8 104 | 1 1 1 1 1 0.8 1 105 | 1 0.8 1 0.8 1 0.8 1 106 | 0.8 1 1 1 1 0.8 1 107 | 0.4 0.8 0.2 0.8 0.8 0.8 0.6 108 | 1 1 0.8 0.8 1 1 1 109 | 0.8 1 1 1 1 1 1 110 | 0.8 0.8 0.8 0.8 0.8 1 1 111 | 1 1 1 1 1 0.6 0.8 112 | 0.8 0.8 1 1 1 1 1 113 | 0.8 1 0.8 0.8 0.8 1 1 114 | 0.8 0.6 1 0.8 0.8 1 0.8 115 | 1 1 1 1 0.8 1 1 116 | 1 1 1 1 1 1 1 117 | 1 1 1 1 1 1 1 118 | 0.8 0.8 1 1 1 1 1 119 | 1 1 1 0.8 1 0.8 0.8 120 | 0.8 1 1 0.8 1 0.8 0.8 121 | 0.6 0.8 0.4 0.4 0.4 0.4 0.4 122 | 0.8 1 1 1 1 1 1 123 | 1 0.8 1 1 1 1 1 124 | 1 0.8 0.8 0.8 0.8 1 0.8 125 | 1 1 1 1 1 1 1 126 | 1 0.8 1 1 1 1 1 127 | 0.8 1 1 1 1 1 1 128 | 0.8 1 0.8 1 1 1 1 129 | 0.6 0.8 0.8 0.6 0.8 0.6 0.6 130 | 0.2 0.8 0.4 0.4 0.6 0.2 0.4 131 | 0.2 0.6 0.6 0.4 0.8 0.8 0.6 132 | -------------------------------------------------------------------------------- /RFM/sources/inst/example/AMEvaluation.r: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulip-lab/open-code/afcc27a3cabf9b5658309b84a9940c8533a397ca/RFM/sources/inst/example/AMEvaluation.r -------------------------------------------------------------------------------- /RFM/sources/inst/example/ChoquetEvaluation.r: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulip-lab/open-code/afcc27a3cabf9b5658309b84a9940c8533a397ca/RFM/sources/inst/example/ChoquetEvaluation.r -------------------------------------------------------------------------------- /RFM/sources/inst/example/DataAnalysisRoutine.r: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulip-lab/open-code/afcc27a3cabf9b5658309b84a9940c8533a397ca/RFM/sources/inst/example/DataAnalysisRoutine.r -------------------------------------------------------------------------------- /RFM/sources/inst/example/PreferenceAnalysisExample.r: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulip-lab/open-code/afcc27a3cabf9b5658309b84a9940c8533a397ca/RFM/sources/inst/example/PreferenceAnalysisExample.r -------------------------------------------------------------------------------- /RFM/sources/inst/example/WAMEvaluation.r: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulip-lab/open-code/afcc27a3cabf9b5658309b84a9940c8533a397ca/RFM/sources/inst/example/WAMEvaluation.r -------------------------------------------------------------------------------- /RFM/sources/inst/example/data.txt: -------------------------------------------------------------------------------- 1 | 0.6 0.9 0.5 0.8 2 | 0.8 0.3 0.4 0.3 3 | 0.2 0.6 0.3 0.4 4 | 0.7 1 0.5 0.8 5 | 0.3 0.6 0.8 0.7 6 | 0.5 0.4 0.3 0.5 7 | 0.8 0.9 0.7 0.9 8 | 0.3 0.8 0.9 0.6 9 | 0.6 0.8 0.4 0.5 10 | 0.3 0.6 0.2 0.2 -------------------------------------------------------------------------------- /RFM/sources/man/Rfmtool.Rd: -------------------------------------------------------------------------------- 1 | \name{Rfmtool} 2 | \alias{Rfmtool} 3 | %- Also NEED an '\alias' for EACH other topic documented here. 4 | \title{Rfmtool package 5 | } 6 | \description{ 7 | Programming library of fuzzy measure which provides various tools for handling fuzzy measures, 8 | calculating Shapley value and Interaction index, Choquet integrals, 9 | as well as fitting fuzzy measures to empirical data. 10 | %% ~~ A concise (1-5 lines) description of what the function does. ~~ 11 | } 12 | \usage{ 13 | fm.fitting(data, kadd): this estimates the fuzzy measure based on the empirical data. 14 | 15 | fm.Choquet(x, v): this calculates the Choquet Integral based on the general fuzzy measure. 16 | 17 | fm.ChoquetMob(x, Mob): this calculates the Choquet Integral based on the Mobius fuzzy measure. 18 | 19 | fm.Mobius(v): transforms the general fuzzy measure v into the Mobius representation. 20 | 21 | fm.Zeta(Mob): transforms the Mobius fuzzy measure Mob to the general representation. 22 | 23 | fm.Shapley(v): calculates the Shapley value from the general fuzzy measure v. 24 | 25 | fm.Interaction(Mob): calculates the Interaction Index from the Mobius fuzzy 26 | measure Mob. 27 | 28 | } 29 | %- maybe also 'usage' for other objects documented here. 30 | \details{For more detail about the usage of each function. 31 | Please use the following command in the R environment. 32 | 33 | help(fm.fitting) 34 | 35 | help(fm.Choquet) 36 | 37 | help(fm.ChoquetMob) 38 | 39 | help(fm.Mobius) 40 | 41 | help(fm.Zeta) 42 | 43 | help(fm.Shapley) 44 | 45 | help(fm.Interaction) 46 | 47 | %% ~~ If necessary, more details than the description above ~~ 48 | 49 | } 50 | \value{ 51 | %% ~Describe the value returned 52 | %% If it is a LIST, use 53 | %% \item{comp1 }{Description of 'comp1'} 54 | %% \item{comp2 }{Description of 'comp2'} 55 | %% ... 56 | } 57 | \references{ 58 | %% ~put references to the literature/web site here ~ 59 | } 60 | \author{ 61 | %% ~~who you are~~ 62 | } 63 | \note{ 64 | %% ~~further notes~~ 65 | } 66 | 67 | %% ~Make other sections like Warning with \section{Warning }{....} ~ 68 | 69 | \seealso{ 70 | %% ~~objects to See Also as \code{\link{help}}, ~~~ 71 | } 72 | % Add one or more standard keywords, see file 'KEYWORDS' in the 73 | % R documentation directory. 74 | \keyword{ ~kwd1 } 75 | \keyword{ ~kwd2 }% __ONLY ONE__ keyword per line 76 | -------------------------------------------------------------------------------- /RFM/sources/man/fm.Choquet.Rd: -------------------------------------------------------------------------------- 1 | \name{fm.Choquet} 2 | \alias{fm.Choquet} 3 | %- Also NEED an '\alias' for EACH other topic documented here. 4 | \title{Choquet function 5 | 6 | } 7 | \description{ 8 | Calculates the value of a descrete Choquet integral of input x, with fuzzy measure in general representation 9 | %% ~~ A concise (1-5 lines) description of what the function does. ~~ 10 | } 11 | \usage{ 12 | fm.Choquet(x, v) 13 | } 14 | %- maybe also 'usage' for other objects documented here. 15 | \arguments{ 16 | \item{x}{input vector of size n, containing utility value of input criteria. 17 | x is in [0,1]. 18 | %% ~~Describe \code{x} here~~ 19 | } 20 | \item{v}{the genral fuzzy measure of size m=2^n. Its values can be provided by users, 21 | or by estimating from emperical data. 22 | %% ~~Describe \code{v} here~~ 23 | } 24 | \item{output}{the ouput is a single value of the computed Choquet integral.} 25 | } 26 | \details{ 27 | %% ~~ If necessary, more details than the description above ~~ 28 | } 29 | \value{ 30 | %% ~Describe the value returned 31 | %% If it is a LIST, use 32 | %% \item{comp1 }{Description of 'comp1'} 33 | %% \item{comp2 }{Description of 'comp2'} 34 | %% ... 35 | } 36 | \references{ 37 | %% ~put references to the literature/web site here ~ 38 | } 39 | \author{ 40 | %% ~~who you are~~ 41 | } 42 | \note{ 43 | %% ~~further notes~~ 44 | } 45 | 46 | %% ~Make other sections like Warning with \section{Warning }{....} ~ 47 | 48 | \seealso{ 49 | %% ~~objects to See Also as \code{\link{help}}, ~~~ 50 | } 51 | \examples{ 52 | ##---- Should be DIRECTLY executable !! ---- 53 | fm.Choquet(c(0.6, 0.3, 0.8), c(0, 0.3, 0.5, 0.6, 0.4, 0.8, 0.7, 1)) 54 | ## The function is currently defined as 55 | function(x,v) 56 | { 57 | #Calculates the value of a discrete Choquet integral of an input x, with provided fuzzy measure v (in general representation) 58 | 59 | ChoquetVal <- -1; #this is a default initial value. 60 | ChoquetValue <- .C("ChoquetCall", as.numeric(x), 61 | as.numeric(v), 62 | as.integer(length(x)), 63 | out = as.numeric(ChoquetVal)); 64 | return (ChoquetValue$out); 65 | } 66 | # This is a wrapper function which calls the main computation procedure in C/C++ code. 67 | } 68 | % Add one or more standard keywords, see file 'KEYWORDS' in the 69 | % R documentation directory. 70 | \keyword{ ~kwd1 } 71 | \keyword{ ~kwd2 }% __ONLY ONE__ keyword per line 72 | -------------------------------------------------------------------------------- /RFM/sources/man/fm.ChoquetMob.Rd: -------------------------------------------------------------------------------- 1 | \name{fm.ChoquetMob} 2 | \alias{fm.ChoquetMob} 3 | %- Also NEED an '\alias' for EACH other topic documented here. 4 | \title{ChoquetMob function 5 | 6 | } 7 | \description{ 8 | This is an alternative calculation of the Choquet integral from the fuzzy measure in Mobius representation. 9 | %% ~~ A concise (1-5 lines) description of what the function does. ~~ 10 | } 11 | \usage{ 12 | fm.ChoquetMob(x, Mob) 13 | } 14 | %- maybe also 'usage' for other objects documented here. 15 | \arguments{ 16 | \item{x}{input vector of size n, containing utility value of input criteria. 17 | x is in [0,1]. 18 | %% ~~Describe \code{x} here~~ 19 | } 20 | \item{Mob}{the Mobius fuzzy measure of size m=2^n. Its values can be provided by users, 21 | or by estimating from emperical data. 22 | %% ~~Describe \code{Mob} here~~ 23 | } 24 | \item{output}{the ouput is a single value of the computed Choquet integral.} 25 | } 26 | \details{ 27 | %% ~~ If necessary, more details than the description above ~~ 28 | } 29 | \value{ 30 | %% ~Describe the value returned 31 | %% If it is a LIST, use 32 | %% \item{comp1 }{Description of 'comp1'} 33 | %% \item{comp2 }{Description of 'comp2'} 34 | %% ... 35 | } 36 | \references{ 37 | %% ~put references to the literature/web site here ~ 38 | } 39 | \author{ 40 | %% ~~who you are~~ 41 | } 42 | \note{ 43 | %% ~~further notes~~ 44 | } 45 | 46 | %% ~Make other sections like Warning with \section{Warning }{....} ~ 47 | 48 | \seealso{ 49 | %% ~~objects to See Also as \code{\link{help}}, ~~~ 50 | } 51 | \examples{ 52 | ##---- Should be DIRECTLY executable !! ---- 53 | fm.ChoquetMob(c(0.6, 0.3, 0.8), c(0.0, 0.3, 0.5, -0.2, 0.4, 0.1, -0.2, 0.1)) 54 | ## The function is currently defined as 55 | function(x,Mob) 56 | { 57 | ChoquetVal <- -1; #this is just a initial value. 58 | ChoquetMobValue <- .C("ChoquetMobCall", as.numeric(x), 59 | as.numeric(Mob), 60 | as.integer(length(x)), 61 | out = as.numeric(ChoquetVal)); 62 | return (ChoquetMobValue$out); 63 | 64 | } 65 | # This is a wrapper function which calls the main computation procedure in C/C++ code. 66 | } 67 | % Add one or more standard keywords, see file 'KEYWORDS' in the 68 | % R documentation directory. 69 | \keyword{ ~kwd1 } 70 | \keyword{ ~kwd2 }% __ONLY ONE__ keyword per line 71 | -------------------------------------------------------------------------------- /RFM/sources/man/fm.Interaction.Rd: -------------------------------------------------------------------------------- 1 | \name{fm.Interaction} 2 | \alias{fm.Interaction} 3 | %- Also NEED an '\alias' for EACH other topic documented here. 4 | \title{Interaction Index computation function 5 | 6 | } 7 | \description{Calculates all the interaction indices of input criteria from Mobius fuzzy measure. 8 | %% ~~ A concise (1-5 lines) description of what the function does. ~~ 9 | } 10 | \usage{ 11 | fm.Interaction(Mob) 12 | } 13 | %- maybe also 'usage' for other objects documented here. 14 | \arguments{ 15 | \item{Mob}{fuzzy measure value in Mobius representation} 16 | \item{output}{the output is a matrix, whose first column stores the interaction 17 | index values, and the second column stores the indices of criteria in coalitions.} 18 | } 19 | \details{ 20 | %% ~~ If necessary, more details than the description above ~~ 21 | } 22 | \value{ 23 | %% ~Describe the value returned 24 | %% If it is a LIST, use 25 | %% \item{comp1 }{Description of 'comp1'} 26 | %% \item{comp2 }{Description of 'comp2'} 27 | %% ... 28 | } 29 | \references{ 30 | %% ~put references to the literature/web site here ~ 31 | } 32 | \author{ 33 | %% ~~who you are~~ 34 | } 35 | \note{ 36 | %% ~~further notes~~ 37 | } 38 | 39 | %% ~Make other sections like Warning with \section{Warning }{....} ~ 40 | 41 | \seealso{ 42 | %% ~~objects to See Also as \code{\link{help}}, ~~~ 43 | } 44 | \examples{ 45 | ##---- Should be DIRECTLY executable !! ---- 46 | fm.Interaction(c( 0.0, 0.3, 0.5, -0.2, 0.4, 0.1, -0.2, 0.1)) 47 | ## The function is currently defined as 48 | function(Mob) 49 | { 50 | coliation <- array(0,length(Mob)); 51 | InteractionVal <- array(0,length(Mob)); 52 | InteractionValue <- .C("InteractionCall", as.numeric(Mob), 53 | inter = as.numeric(InteractionVal), 54 | as.integer(log2(length(Mob))), 55 | colia = as.integer(coliation)); 56 | inteIndex <- as.matrix(InteractionValue$inter); 57 | coliaIndex <- as.matrix(InteractionValue$colia); 58 | index <- cbind(inteIndex,coliaIndex); 59 | return (round(index, digits=4)); 60 | 61 | } 62 | # This is a wrapper function which calls the main computation procedure in C/C++ code. 63 | } 64 | % Add one or more standard keywords, see file 'KEYWORDS' in the 65 | % R documentation directory. 66 | \keyword{ ~kwd1 } 67 | \keyword{ ~kwd2 }% __ONLY ONE__ keyword per line 68 | -------------------------------------------------------------------------------- /RFM/sources/man/fm.Mobius.Rd: -------------------------------------------------------------------------------- 1 | \name{fm.Mobius} 2 | \alias{fm.Mobius} 3 | %- Also NEED an '\alias' for EACH other topic documented here. 4 | \title{Mobius transform function 5 | 6 | } 7 | \description{calculates Mobius representation of general fuzzy measure, 8 | the input and output is an array of size 2^n=m in binary ordering. 9 | %% ~~ A concise (1-5 lines) description of what the function does. ~~ 10 | } 11 | \usage{ 12 | fm.Mobius(v) 13 | } 14 | %- maybe also 'usage' for other objects documented here. 15 | \arguments{ 16 | \item{v}{fuzzy measure value in standard representation.} 17 | \item{output}{the output is the fuzzy measure in Mobius representation.} 18 | } 19 | \details{ 20 | %% ~~ If necessary, more details than the description above ~~ 21 | } 22 | \value{ 23 | %% ~Describe the value returned 24 | %% If it is a LIST, use 25 | %% \item{comp1 }{Description of 'comp1'} 26 | %% \item{comp2 }{Description of 'comp2'} 27 | %% ... 28 | } 29 | \references{ 30 | %% ~put references to the literature/web site here ~ 31 | } 32 | \author{ 33 | %% ~~who you are~~ 34 | } 35 | \note{ 36 | %% ~~further notes~~ 37 | } 38 | 39 | %% ~Make other sections like Warning with \section{Warning }{....} ~ 40 | 41 | \seealso{ 42 | %% ~~objects to See Also as \code{\link{help}}, ~~~ 43 | } 44 | \examples{ 45 | ##---- Should be DIRECTLY executable !! ---- 46 | fm.Mobius(c(0, 0.3, 0.5, 0.6, 0.4, 0.8, 0.7, 1)) 47 | ## The function is currently defined as 48 | function(v) 49 | { 50 | MobiusVal <- array(0,length(v)); 51 | MobiusValue <- .C("MobiusCall", as.numeric(v), 52 | out = as.numeric(MobiusVal), 53 | as.integer(log2(length(v)))); 54 | 55 | return (MobiusValue$out); 56 | } 57 | # This is a wrapper function which calls the main computation procedure in C/C++ code. 58 | } 59 | % Add one or more standard keywords, see file 'KEYWORDS' in the 60 | % R documentation directory. 61 | \keyword{ ~kwd1 } 62 | \keyword{ ~kwd2 }% __ONLY ONE__ keyword per line 63 | -------------------------------------------------------------------------------- /RFM/sources/man/fm.Rd: -------------------------------------------------------------------------------- 1 | \name{fm} 2 | \alias{fm} 3 | %- Also NEED an '\alias' for EACH other topic documented here. 4 | \title{Rfmtool package 5 | } 6 | \description{This function shows a list of function included in this toolbox 7 | %% ~~ A concise (1-5 lines) description of what the function does. ~~ 8 | } 9 | \usage{ 10 | fm() 11 | } 12 | %- maybe also 'usage' for other objects documented here. 13 | \details{%% ~~ If necessary, more details than the description above ~~ 14 | } 15 | \value{ 16 | %% ~Describe the value returned 17 | %% If it is a LIST, use 18 | %% \item{comp1 }{Description of 'comp1'} 19 | %% \item{comp2 }{Description of 'comp2'} 20 | %% ... 21 | } 22 | \references{ 23 | %% ~put references to the literature/web site here ~ 24 | } 25 | \author{ 26 | %% ~~who you are~~ 27 | } 28 | \note{ 29 | %% ~~further notes~~ 30 | } 31 | 32 | %% ~Make other sections like Warning with \section{Warning }{....} ~ 33 | 34 | \seealso{ 35 | %% ~~objects to See Also as \code{\link{help}}, ~~~ 36 | } 37 | \examples{ 38 | ##---- Should be DIRECTLY executable !! ---- 39 | fm() 40 | ## The function is currently defined as 41 | function() 42 | { 43 | print("A list of functions in Rfmtool Tool Box:") 44 | 45 | print("fm.fitting(data,kadd)") 46 | print("fm.Choquet(x,v)") 47 | print("fm.ChoquetMob(x,Mob)") 48 | print("fm.Mobius(v)") 49 | print("fm.Zeta(Mob)") 50 | print("fm.Shapley(v)") 51 | print("fm.Interaction(Mob)") 52 | print("fm.test()") 53 | } 54 | } 55 | % Add one or more standard keywords, see file 'KEYWORDS' in the 56 | % R documentation directory. 57 | \keyword{ ~kwd1 } 58 | \keyword{ ~kwd2 }% __ONLY ONE__ keyword per line 59 | -------------------------------------------------------------------------------- /RFM/sources/man/fm.Shapley.Rd: -------------------------------------------------------------------------------- 1 | \name{fm.Shapley} 2 | \alias{fm.Shapley} 3 | %- Also NEED an '\alias' for EACH other topic documented here. 4 | \title{Shapley value computation function 5 | } 6 | \description{Calculates the Shapley values of input criteria from general fuzzy measure, 7 | %% ~~ A concise (1-5 lines) description of what the function does. ~~ 8 | } 9 | \usage{ 10 | fm.Shapley(v) 11 | } 12 | %- maybe also 'usage' for other objects documented here. 13 | \arguments{ 14 | \item{v}{is fuzzy measure in general representation.} 15 | \item{output}{The output is an array of size n, which contain Shapley values of input criteria.} 16 | } 17 | \details{ 18 | %% ~~ If necessary, more details than the description above ~~ 19 | } 20 | \value{ 21 | %% ~Describe the value returned 22 | %% If it is a LIST, use 23 | %% \item{comp1 }{Description of 'comp1'} 24 | %% \item{comp2 }{Description of 'comp2'} 25 | %% ... 26 | } 27 | \references{ 28 | %% ~put references to the literature/web site here ~ 29 | } 30 | \author{ 31 | %% ~~who you are~~ 32 | } 33 | \note{ 34 | %% ~~further notes~~ 35 | } 36 | 37 | %% ~Make other sections like Warning with \section{Warning }{....} ~ 38 | 39 | \seealso{ 40 | %% ~~objects to See Also as \code{\link{help}}, ~~~ 41 | } 42 | \examples{ 43 | ##---- Should be DIRECTLY executable !! ---- 44 | fm.Shapley(c(0, 0.3, 0.5, 0.6, 0.4, 0.8, 0.7, 1)) 45 | ## The function is currently defined as 46 | function(v) 47 | { 48 | ShapleyVal <- 1:log2(length(v)); 49 | ShapleyValue <- .C("ShapleyCall", as.numeric(v), 50 | out = as.numeric(ShapleyVal), 51 | as.integer(log2(length(v)))); 52 | 53 | return (ShapleyValue$out); 54 | 55 | } 56 | # This is a wrapper function which calls the main computation procedure in C/C++ code. 57 | } 58 | % Add one or more standard keywords, see file 'KEYWORDS' in the 59 | % R documentation directory. 60 | \keyword{ ~kwd1 } 61 | \keyword{ ~kwd2 }% __ONLY ONE__ keyword per line 62 | -------------------------------------------------------------------------------- /RFM/sources/man/fm.Zeta.Rd: -------------------------------------------------------------------------------- 1 | \name{fm.Zeta} 2 | \alias{fm.Zeta} 3 | \title{Zeta transform function} 4 | %% ~~function to do ... ~~ 5 | \description{Calculates the general fuzzy measure from Mobius representation. 6 | the input and output is an array of size 2^n=m in binary ordering. 7 | %% ~~ A concise (1-5 lines) description of what the function does. ~~ 8 | } 9 | \usage{fm.Zeta(Mob)} 10 | %- maybe also 'usage' for other objects documented here. 11 | \arguments{ 12 | \item{Mob}{ fuzzy measure value in Mobius representation. 13 | } 14 | \item{output}{the output is the fuzzy measure in general representation.} 15 | } 16 | \details{ 17 | %% ~~ If necessary, more details than the description above ~~ 18 | } 19 | \value{ 20 | %% ~Describe the value returned 21 | %% If it is a LIST, use 22 | %% \item{comp1 }{Description of 'comp1'} 23 | %% \item{comp2 }{Description of 'comp2'} 24 | %% ... 25 | } 26 | \references{ 27 | %% ~put references to the literature/web site here ~ 28 | } 29 | \author{ 30 | %% ~~who you are~~ 31 | } 32 | \note{ 33 | %% ~~further notes~~ 34 | } 35 | 36 | %% ~Make other sections like Warning with \section{Warning }{....} ~ 37 | 38 | \seealso{ 39 | %% ~~objects to See Also as \code{\link{help}}, ~~~ 40 | } 41 | \examples{ 42 | ##---- Should be DIRECTLY executable !! ---- 43 | fm.Zeta(c(0, 0.18, 0.15, -0.05, 0.23, 0.07, 0.18, 0.24)) 44 | ## The function is currently defined as 45 | function(Mob) 46 | { 47 | ZetaVal <- array(0,length(Mob)); 48 | ZetaValue <- .C("ZetaCall", as.numeric(Mob), 49 | out = as.numeric(ZetaVal), 50 | as.integer(log2(length(Mob)))); 51 | 52 | return (ZetaValue$out); 53 | 54 | } 55 | # This is a wrapper function which calls the main computation procedure in C/C++ code. 56 | } 57 | % Add one or more standard keywords, see file 'KEYWORDS' in the 58 | % R documentation directory. 59 | \keyword{ ~kwd1 } 60 | \keyword{ ~kwd2 }% __ONLY ONE__ keyword per line 61 | -------------------------------------------------------------------------------- /RFM/sources/man/fm.fitting.Rd: -------------------------------------------------------------------------------- 1 | \name{fm.fitting} 2 | \alias{fm.fitting} 3 | %- Also NEED an '\alias' for EACH other topic documented here. 4 | \title{Fuzzy Measure Fitting function 5 | 6 | } 7 | \description{ 8 | Esimate values of the fuzzy measures from empirical data. 9 | %% ~~ A concise (1-5 lines) description of what the function does. ~~ 10 | } 11 | \usage{ 12 | fm.fitting(data, kadd) 13 | } 14 | %- maybe also 'usage' for other objects documented here. 15 | \arguments{ 16 | \item{data}{is the empirical data set in pairs (x_1,y_1),(x_2,y_2),...,(x_d,y_d) 17 | where x_i in [0,1]^n is a vector contains utility values of n input criteria 18 | {x_{i1},x_{i2},...,x_{in}}, 19 | y_i in [0,1] is a single aggregated value given by decision makers. 20 | The data is stored 21 | as a matrix of M by n+1 elements, where M is the number of data instances, 22 | and n is the number of input criteria, 23 | the column n + 1 store the observed aggregating value y. 24 | %% ~~Describe \code{x} here~~ 25 | } 26 | \item{kadd}{is the value of k-additivity, which is used for 27 | reducing the complexity of fuzzy measures. 28 | kadd is defined as an optional argument, its default 29 | value is kadd = n. 30 | %% ~~Describe \code{v} here~~ 31 | } 32 | \item{output}{ The output result of the fitting function is an array of size 2^n 33 | containing estimated Mobius fuzzy measure in binary ordering.} 34 | } 35 | \details{ 36 | %% ~~ If necessary, more details than the description above ~~ 37 | } 38 | \value{ 39 | %% ~Describe the value returned 40 | %% If it is a LIST, use 41 | %% \item{comp1 }{Description of 'comp1'} 42 | %% \item{comp2 }{Description of 'comp2'} 43 | %% ... 44 | } 45 | \references{ 46 | %% ~put references to the literature/web site here ~ 47 | } 48 | \author{ 49 | %% ~~who you are~~ 50 | } 51 | \note{ 52 | %% ~~further notes~~ 53 | } 54 | 55 | %% ~Make other sections like Warning with \section{Warning }{....} ~ 56 | 57 | \seealso{ 58 | %% ~~objects to See Also as \code{\link{help}}, ~~~ 59 | } 60 | \examples{ 61 | ## The function is currently defined as 62 | function(data,kadd="NA",...) 63 | { 64 | size <- dim(as.matrix(data)); 65 | n <- size[2] - 1; 66 | datanum <- size[1]; 67 | m = 2^n; 68 | MobiusVal <- array(0,m); 69 | 70 | if (kadd == "NA") 71 | { 72 | kadd = n; 73 | } 74 | 75 | MobiusValue <- .C("fittingCall", as.integer(n), 76 | as.integer(datanum), 77 | as.integer(kadd), 78 | out = as.numeric(MobiusVal), 79 | as.numeric(t(data))); 80 | 81 | return (MobiusValue$out); 82 | } 83 | # This is a wrapper function which calls the main computation procedure in C/C++ code. 84 | } 85 | % Add one or more standard keywords, see file 'KEYWORDS' in the 86 | % R documentation directory. 87 | \keyword{ ~kwd1 } 88 | \keyword{ ~kwd2 }% __ONLY ONE__ keyword per line 89 | -------------------------------------------------------------------------------- /RFM/sources/man/fm.test.Rd: -------------------------------------------------------------------------------- 1 | \name{fm.test} 2 | \alias{fm.test} 3 | %- Also NEED an '\alias' for EACH other topic documented here. 4 | \title{A Test function 5 | %% ~~function to do ... ~~ 6 | } 7 | \description{ 8 | This function provide some examples of how fuzzy measure operation functions in this toolbox are used. 9 | It can be used to test if the toolbox has been installed successfully or not. 10 | } 11 | \usage{ 12 | fm.test() 13 | } 14 | %- maybe also 'usage' for other objects documented here. 15 | \details{ 16 | %% ~~ If necessary, more details than the description above ~~ 17 | } 18 | \value{ 19 | %% ~Describe the value returned 20 | %% If it is a LIST, use 21 | %% \item{comp1 }{Description of 'comp1'} 22 | %% \item{comp2 }{Description of 'comp2'} 23 | %% ... 24 | } 25 | \references{ 26 | %% ~put references to the literature/web site here ~ 27 | } 28 | \author{ 29 | 30 | } 31 | \note{ 32 | %% ~~further notes~~ 33 | } 34 | 35 | %% ~Make other sections like Warning with \section{Warning }{....} ~ 36 | 37 | \seealso{ 38 | %% ~~objects to See Also as \code{\link{help}}, ~~~ 39 | } 40 | \examples{ 41 | ## The function is currently defined as 42 | function () 43 | { 44 | print("Choquet Integral from general fuzzy measure") 45 | print(fm.Choquet(c(0.6, 0.3, 0.8), c(0, 0.3, 0.5, 0.6, 0.4, 0.8, 0.7, 1))) 46 | 47 | print("Choquet Integral from Mobius fuzzy measure") 48 | print(fm.ChoquetMob(c(0.6, 0.3, 0.8), c(0.0, 0.3, 0.5, -0.2, 0.4, 0.1, -0.2, 0.1))) 49 | 50 | print("Mobius transform") 51 | print(fm.Mobius(c(0, 0.3, 0.5, 0.6, 0.4, 0.8, 0.7, 1))) 52 | 53 | print("Zeta transform") 54 | print(fm.Zeta(c(0, 0.18, 0.15, -0.05, 0.23, 0.07, 0.18, 0.24))) 55 | 56 | print("Shapley value") 57 | print(fm.Shapley(c(0, 0.3, 0.5, 0.6, 0.4, 0.8, 0.7, 1))) 58 | 59 | print("Interaction Index") 60 | print(fm.Zeta(c(0, 0.18, 0.15, -0.05, 0.23, 0.07, 0.18, 0.24))) 61 | } 62 | } 63 | % Add one or more standard keywords, see file 'KEYWORDS' in the 64 | % R documentation directory. 65 | \keyword{ ~kwd1 } 66 | \keyword{ ~kwd2 }% __ONLY ONE__ keyword per line 67 | -------------------------------------------------------------------------------- /RFM/sources/src/Makevars: -------------------------------------------------------------------------------- 1 | PKG_CPPFLAGS=-I . -DINTEGERTIME -DPARSER_LP -DBUILDING_FOR_R -DYY_NEVER_INTERACTIVE -DUSRDLL -DCLOCKTIME -DRoleIsExternalInvEngine -DINVERSE_ACTIVE=INVERSE_LUSOL -DINLINE=static -DParanoia 2 | -------------------------------------------------------------------------------- /RFM/sources/src/Makevars.win: -------------------------------------------------------------------------------- 1 | PKG_CPPFLAGS=-I . -DINTEGERTIME -DPARSER_LP -DBUILDING_FOR_R -DYY_NEVER_INTERACTIVE -DUSRDLL -DCLOCKTIME -DRoleIsExternalInvEngine -DINVERSE_ACTIVE=INVERSE_LUSOL -DWIN32 -DINLINE=static -DParanoia 2 | -------------------------------------------------------------------------------- /RFM/sources/src/declare.h: -------------------------------------------------------------------------------- 1 | #ifndef __DECLARE_H__ 2 | #define __DECLARE_H__ 3 | 4 | #if !defined ANSI_PROTOTYPES 5 | # if defined MSDOS || defined __BORLANDC__ || defined __HIGHC__ || defined SCO_UNIX || defined AViiON 6 | # define ANSI_PROTOTYPES 1 7 | # endif 8 | #endif 9 | 10 | #if ANSI_PROTOTYPES!=0 11 | # define __OF(args) args 12 | #else 13 | # define __OF(args) () 14 | #endif 15 | 16 | #if defined __HIGHC__ 17 | # define VARARG ... 18 | #else 19 | # define VARARG 20 | #endif 21 | 22 | #endif 23 | -------------------------------------------------------------------------------- /RFM/sources/src/hbio.h: -------------------------------------------------------------------------------- 1 | #ifndef IOHB_H 2 | #define IOHB_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | int readHB_info(const char* filename, int* M, int* N, int* nz, char** Type, 13 | int* Nrhs); 14 | 15 | int readHB_header(FILE* in_file, char* Title, char* Key, char* Type, 16 | int* Nrow, int* Ncol, int* Nnzero, int* Nrhs, int* Nrhsix, 17 | char* Ptrfmt, char* Indfmt, char* Valfmt, char* Rhsfmt, 18 | int* Ptrcrd, int* Indcrd, int* Valcrd, int* Rhscrd, 19 | char *Rhstype); 20 | 21 | int readHB_mat_double(const char* filename, int colptr[], int rowind[], 22 | double val[]); 23 | 24 | int readHB_newmat_double(const char* filename, int* M, int* N, int* nonzeros, 25 | int** colptr, int** rowind, double** val); 26 | 27 | int readHB_aux_double(const char* filename, const char AuxType, double b[]); 28 | 29 | int readHB_newaux_double(const char* filename, const char AuxType, double** b); 30 | 31 | int writeHB_mat_double(const char* filename, int M, int N, 32 | int nz, const int colptr[], const int rowind[], 33 | const double val[], int Nrhs, const double rhs[], 34 | const double guess[], const double exact[], 35 | const char* Title, const char* Key, const char* Type, 36 | char* Ptrfmt, char* Indfmt, char* Valfmt, char* Rhsfmt, 37 | const char* Rhstype); 38 | 39 | int readHB_mat_char(const char* filename, int colptr[], int rowind[], 40 | char val[], char* Valfmt); 41 | 42 | int readHB_newmat_char(const char* filename, int* M, int* N, int* nonzeros, int** colptr, 43 | int** rowind, char** val, char** Valfmt); 44 | 45 | int readHB_aux_char(const char* filename, const char AuxType, char b[]); 46 | 47 | int readHB_newaux_char(const char* filename, const char AuxType, char** b, char** Rhsfmt); 48 | 49 | int writeHB_mat_char(const char* filename, int M, int N, 50 | int nz, const int colptr[], const int rowind[], 51 | const char val[], int Nrhs, const char rhs[], 52 | const char guess[], const char exact[], 53 | const char* Title, const char* Key, const char* Type, 54 | char* Ptrfmt, char* Indfmt, char* Valfmt, char* Rhsfmt, 55 | const char* Rhstype); 56 | 57 | int ParseIfmt(char* fmt, int* perline, int* width); 58 | 59 | int ParseRfmt(char* fmt, int* perline, int* width, int* prec, int* flag); 60 | 61 | void IOHBTerminate(char* message); 62 | 63 | #ifdef __cplusplus 64 | } 65 | #endif 66 | 67 | #endif 68 | -------------------------------------------------------------------------------- /RFM/sources/src/ini.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "ini.h" 6 | 7 | FILE *ini_create(char *filename) 8 | { 9 | FILE *fp; 10 | 11 | fp = fopen(filename, "w"); 12 | 13 | return(fp); 14 | } 15 | 16 | FILE *ini_open(char *filename) 17 | { 18 | FILE *fp; 19 | 20 | fp = fopen(filename, "r"); 21 | 22 | return(fp); 23 | } 24 | 25 | void ini_writecomment(FILE *fp, char *comment) 26 | { 27 | fprintf(fp, "; %s\n", comment); 28 | } 29 | 30 | void ini_writeheader(FILE *fp, char *header, int addnewline) 31 | { 32 | if((addnewline) && (ftell(fp) > 0)) 33 | fputs("\n", fp); 34 | fprintf(fp, "[%s]\n", header); 35 | } 36 | 37 | void ini_writedata(FILE *fp, char *name, char *data) 38 | { 39 | if(name != NULL) 40 | fprintf(fp, "%s=%s\n", name, data); 41 | else 42 | fprintf(fp, "%s\n", data); 43 | } 44 | 45 | int ini_readdata(FILE *fp, char *data, int szdata, int withcomment) 46 | { 47 | int l; 48 | char *ptr; 49 | 50 | if(fgets(data, szdata, fp) == NULL) 51 | return(0); 52 | 53 | if(!withcomment) { 54 | ptr = strchr(data, ';'); 55 | if(ptr != NULL) 56 | *ptr = 0; 57 | } 58 | 59 | l = strlen(data); 60 | while((l > 0) && (isspace(data[l - 1]))) 61 | l--; 62 | data[l] = 0; 63 | if((l >= 2) && (data[0] == '[') && (data[l - 1] == ']')) { 64 | memcpy(data, data + 1, l - 2); 65 | data[l - 2] = 0; 66 | return(1); 67 | } 68 | return(2); 69 | } 70 | 71 | void ini_close(FILE *fp) 72 | { 73 | fclose(fp); 74 | } 75 | -------------------------------------------------------------------------------- /RFM/sources/src/ini.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | extern FILE *ini_create(char *filename); 4 | extern FILE *ini_open(char *filename); 5 | extern void ini_writecomment(FILE *fp, char *comment); 6 | extern void ini_writeheader(FILE *fp, char *header, int addnewline); 7 | extern void ini_writedata(FILE *fp, char *name, char *data); 8 | extern int ini_readdata(FILE *fp, char *data, int szdata, int withcomment); 9 | extern void ini_close(FILE *fp); 10 | -------------------------------------------------------------------------------- /RFM/sources/src/isfixedvar.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | #include "lp_types.h" 8 | #include "lp_utils.h" 9 | #include "lp_lib.h" 10 | 11 | MYBOOL is_fixedvar(lprec *lp, int variable) 12 | { 13 | if((lp->bb_bounds != NULL && lp->bb_bounds->UBzerobased) || (variable <= lp->rows)) 14 | return( (MYBOOL) (lp->upbo[variable] < lp->epsprimal) ); 15 | else 16 | return( (MYBOOL) (lp->upbo[variable]-lp->lowbo[variable] < lp->epsprimal) ); 17 | } /* is_fixedvar */ 18 | 19 | 20 | -------------------------------------------------------------------------------- /RFM/sources/src/lp_Hash.h: -------------------------------------------------------------------------------- 1 | #ifndef HEADER_lp_hash 2 | #define HEADER_lp_hash 3 | 4 | /* For row and column name hash tables */ 5 | 6 | typedef struct _hashelem 7 | { 8 | char *name; 9 | int index; 10 | struct _hashelem *next; 11 | struct _hashelem *nextelem; 12 | } hashelem; 13 | 14 | typedef struct _hashtable 15 | { 16 | hashelem **table; 17 | int size; 18 | int base; 19 | int count; 20 | struct _hashelem *first; 21 | struct _hashelem *last; 22 | } hashtable; 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | STATIC hashtable *create_hash_table(int size, int base); 29 | STATIC void free_hash_table(hashtable *ht); 30 | STATIC hashelem *findhash(const char *name, hashtable *ht); 31 | STATIC hashelem *puthash(const char *name, int index, hashelem **list, hashtable *ht); 32 | STATIC void drophash(const char *name, hashelem **list, hashtable *ht); 33 | STATIC void free_hash_item(hashelem **hp); 34 | STATIC hashtable *copy_hash_table(hashtable *ht, hashelem **list, int newsize); 35 | STATIC int find_var(lprec *lp, char *name, MYBOOL verbose); 36 | STATIC int find_row(lprec *lp, char *name, MYBOOL Unconstrained_rows_found); 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | 42 | #endif /* HEADER_lp_hash */ 43 | 44 | -------------------------------------------------------------------------------- /RFM/sources/src/lp_LUSOL.h: -------------------------------------------------------------------------------- 1 | #ifndef HEADER_lp_LUSOL 2 | #define HEADER_lp_LUSOL 3 | 4 | /* Include libraries for this inverse system */ 5 | #include "lp_types.h" 6 | #include "lusol.h" 7 | 8 | /* LUSOL defines */ 9 | #ifdef WIN32 10 | # define LUSOL_UseBLAS 11 | #endif 12 | /*#define MAPSINGULARCOLUMN*/ 13 | #define MATINDEXBASE LUSOL_ARRAYOFFSET /* Inversion engine index start for arrays */ 14 | #define LU_START_SIZE 10000 /* Start size of LU; realloc'ed if needed */ 15 | #define DEF_MAXPIVOT 250 /* Maximum number of pivots before refactorization */ 16 | #define MAX_DELTAFILLIN 2.0 /* Do refactorizations based on sparsity considerations */ 17 | #define TIGHTENAFTER 10 /* Tighten LU pivot criteria only after this number of singularities */ 18 | 19 | /* typedef */ struct _INVrec 20 | { 21 | int status; /* Last operation status code */ 22 | int dimcount; /* The actual number of LU rows/columns */ 23 | int dimalloc; /* The allocated LU rows/columns size */ 24 | int user_colcount; /* The number of user LU columns */ 25 | LUSOLrec *LUSOL; 26 | int col_enter; /* The full index of the entering column */ 27 | int col_leave; /* The full index of the leaving column */ 28 | int col_pos; /* The B column to be changed at the next update using data in value[.]*/ 29 | REAL *value; 30 | REAL *pcol; /* Reference to the elimination vector */ 31 | REAL theta_enter; /* Value of the entering column theta */ 32 | 33 | int max_Bsize; /* The largest B matrix of user variables */ 34 | int max_colcount; /* The maximum number of user columns in LU */ 35 | int max_LUsize; /* The largest NZ-count of LU-files generated */ 36 | int num_refact; /* Number of times the basis was refactored */ 37 | int num_timed_refact; 38 | int num_dense_refact; 39 | double time_refactstart; /* Time since start of last refactorization-pivots cyle */ 40 | double time_refactnext; /* Time estimated to next refactorization */ 41 | int num_pivots; /* Number of pivots since last refactorization */ 42 | int num_singular; /* The total number of singular updates */ 43 | char *opts; 44 | MYBOOL is_dirty; /* Specifies if a column is incompletely processed */ 45 | MYBOOL force_refact; /* Force refactorization at the next opportunity */ 46 | MYBOOL timed_refact; /* Set if timer-driven refactorization should be active */ 47 | MYBOOL set_Bidentity; /* Force B to be the identity matrix at the next refactorization */ 48 | } /* INVrec */; 49 | 50 | 51 | #ifdef __cplusplus 52 | /* namespace LUSOL */ 53 | extern "C" { 54 | #endif 55 | 56 | /* Put function headers here */ 57 | #include "lp_BFP.h" 58 | 59 | #ifdef __cplusplus 60 | } 61 | #endif 62 | 63 | #endif /* HEADER_lp_LUSOL */ 64 | -------------------------------------------------------------------------------- /RFM/sources/src/lp_MDO.h: -------------------------------------------------------------------------------- 1 | #ifndef HEADER_MDO 2 | #define HEADER_MDO 3 | 4 | #include "lp_types.h" 5 | 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | int __WINAPI getMDO(lprec *lp, MYBOOL *usedpos, int *colorder, int *size, MYBOOL symmetric); 12 | 13 | #ifdef __cplusplus 14 | } 15 | #endif 16 | 17 | #endif /* HEADER_MDO */ 18 | 19 | -------------------------------------------------------------------------------- /RFM/sources/src/lp_MPS.h: -------------------------------------------------------------------------------- 1 | #ifndef HEADER_lp_MPS 2 | #define HEADER_lp_MPS 3 | 4 | #include "lp_types.h" 5 | 6 | /* For MPS file reading and writing */ 7 | #define ROWNAMEMASK "R%d" 8 | #define ROWNAMEMASK2 "r%d" 9 | #define COLNAMEMASK "C%d" 10 | #define COLNAMEMASK2 "c%d" 11 | 12 | #define MPSFIXED 1 13 | #define MPSFREE 2 14 | 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | /* Read an MPS file */ 21 | MYBOOL MPS_readfile(lprec **newlp, char *filename, int typeMPS, int verbose); 22 | MYBOOL __WINAPI MPS_readhandle(lprec **newlp, FILE *filehandle, int typeMPS, int verbose); 23 | 24 | /* Write a MPS file to output */ 25 | MYBOOL MPS_writefile(lprec *lp, int typeMPS, char *filename); 26 | MYBOOL MPS_writehandle(lprec *lp, int typeMPS, FILE *output); 27 | 28 | /* Read and write BAS files */ 29 | MYBOOL MPS_readBAS(lprec *lp, int typeMPS, char *filename, char *info); 30 | MYBOOL MPS_writeBAS(lprec *lp, int typeMPS, char *filename); 31 | 32 | #ifdef __cplusplus 33 | } 34 | #endif 35 | 36 | #endif /* HEADER_lp_MPS */ 37 | 38 | -------------------------------------------------------------------------------- /RFM/sources/src/lp_crash.h: -------------------------------------------------------------------------------- 1 | 2 | #ifndef HEADER_lp_crash 3 | #define HEADER_lp_crash 4 | 5 | 6 | #include "lp_types.h" 7 | 8 | #define CRASH_SIMPLESCALE /* Specify if we should use a simple absolute scaling threshold */ 9 | 10 | #define CRASH_THRESHOLD 0.167 11 | #define CRASH_SPACER 10 12 | #define CRASH_WEIGHT 0.500 13 | 14 | 15 | 16 | #ifdef __cplusplus 17 | __EXTERN_C { 18 | #endif 19 | 20 | STATIC MYBOOL crash_basis(lprec *lp); 21 | STATIC MYBOOL guess_basis(lprec *lp, REAL *guessvector, int *basisvector); 22 | 23 | 24 | #ifdef __cplusplus 25 | } 26 | #endif 27 | 28 | #endif /* HEADER_lp_crash */ 29 | 30 | -------------------------------------------------------------------------------- /RFM/sources/src/lp_fortify.h: -------------------------------------------------------------------------------- 1 | #ifdef FORTIFY 2 | 3 | #include "fortify.h" 4 | 5 | #endif 6 | -------------------------------------------------------------------------------- /RFM/sources/src/lp_matrix.c: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulip-lab/open-code/afcc27a3cabf9b5658309b84a9940c8533a397ca/RFM/sources/src/lp_matrix.c -------------------------------------------------------------------------------- /RFM/sources/src/lp_mipbb.h: -------------------------------------------------------------------------------- 1 | #ifndef HEADER_lp_mipbb 2 | #define HEADER_lp_mipbb 3 | 4 | #include "lp_types.h" 5 | #include "lp_utils.h" 6 | 7 | 8 | /* Bounds storage for B&B routines */ 9 | typedef struct _BBrec 10 | { 11 | struct _BBrec *parent; 12 | struct _BBrec *child; 13 | lprec *lp; 14 | int varno; 15 | int vartype; 16 | int lastvarcus; /* Count of non-int variables of the previous branch */ 17 | int lastrcf; 18 | int nodesleft; 19 | int nodessolved; 20 | int nodestatus; 21 | REAL noderesult; 22 | REAL lastsolution; /* Optimal solution of the previous branch */ 23 | REAL sc_bound; 24 | REAL *upbo, *lowbo; 25 | REAL UPbound, LObound; 26 | int UBtrack, LBtrack; /* Signals that incoming bounds were changed */ 27 | MYBOOL contentmode; /* Flag indicating if we "own" the bound vectors */ 28 | MYBOOL sc_canset; 29 | MYBOOL isSOS; 30 | MYBOOL isGUB; 31 | int *varmanaged; /* Extended list of variables managed by this B&B level */ 32 | MYBOOL isfloor; /* State variable indicating the active B&B bound */ 33 | MYBOOL UBzerobased; /* State variable indicating if bounds have been rebased */ 34 | } BBrec; 35 | 36 | #ifdef __cplusplus 37 | extern "C" { 38 | #endif 39 | 40 | STATIC BBrec *create_BB(lprec *lp, BBrec *parentBB, MYBOOL dofullcopy); 41 | STATIC BBrec *push_BB(lprec *lp, BBrec *parentBB, int varno, int vartype, int varcus); 42 | STATIC MYBOOL initbranches_BB(BBrec *BB); 43 | STATIC MYBOOL fillbranches_BB(BBrec *BB); 44 | STATIC MYBOOL nextbranch_BB(BBrec *BB); 45 | STATIC MYBOOL strongbranch_BB(lprec *lp, BBrec *BB, int varno, int vartype, int varcus); 46 | STATIC MYBOOL initcuts_BB(lprec *lp); 47 | STATIC int updatecuts_BB(lprec *lp); 48 | STATIC MYBOOL freecuts_BB(lprec *lp); 49 | STATIC BBrec *findself_BB(BBrec *BB); 50 | STATIC int solve_LP(lprec *lp, BBrec *BB); 51 | STATIC int rcfbound_BB(BBrec *BB, int varno, MYBOOL isINT, REAL *newbound, MYBOOL *isfeasible); 52 | STATIC MYBOOL findnode_BB(BBrec *BB, int *varno, int *vartype, int *varcus); 53 | STATIC int solve_BB(BBrec *BB); 54 | STATIC MYBOOL free_BB(BBrec **BB); 55 | STATIC BBrec *pop_BB(BBrec *BB); 56 | 57 | STATIC int run_BB(lprec *lp); 58 | 59 | #ifdef __cplusplus 60 | } 61 | #endif 62 | 63 | #endif /* HEADER_lp_mipbb */ 64 | 65 | -------------------------------------------------------------------------------- /RFM/sources/src/lp_pricePSE.h: -------------------------------------------------------------------------------- 1 | #ifndef HEADER_lp_pricePSE 2 | #define HEADER_lp_pricePSE 3 | 4 | #include "lp_types.h" 5 | 6 | #define ApplySteepestEdgeMinimum 7 | 8 | #ifdef __cplusplus 9 | extern "C" { 10 | #endif 11 | 12 | /* Price norm management routines */ 13 | STATIC MYBOOL initPricer(lprec *lp); 14 | /* 15 | INLINE MYBOOL applyPricer(lprec *lp); 16 | */ 17 | STATIC void simplexPricer(lprec *lp, MYBOOL isdual); 18 | STATIC void freePricer(lprec *lp); 19 | STATIC MYBOOL resizePricer(lprec *lp); 20 | STATIC REAL getPricer(lprec *lp, int item, MYBOOL isdual); 21 | STATIC MYBOOL restartPricer(lprec *lp, MYBOOL isdual); 22 | STATIC MYBOOL updatePricer(lprec *lp, int rownr, int colnr, REAL *pcol, REAL *prow, int *nzprow); 23 | STATIC MYBOOL verifyPricer(lprec *lp); 24 | 25 | #ifdef __cplusplus 26 | } 27 | #endif 28 | 29 | #endif /* HEADER_lp_pricePSE */ 30 | 31 | -------------------------------------------------------------------------------- /RFM/sources/src/lp_report.h: -------------------------------------------------------------------------------- 1 | #ifndef HEADER_lp_report 2 | #define HEADER_lp_report 3 | 4 | #ifdef __cplusplus 5 | extern "C" { 6 | #endif 7 | 8 | /* General information functions */ 9 | char * __VACALL explain(lprec *lp, char *format, ...); 10 | void __VACALL report(lprec *lp, int level, char *format, ...); 11 | 12 | /* Prototypes for debugging and general data dumps */ 13 | void debug_print(lprec *lp, char *format, ...); 14 | void debug_print_solution(lprec *lp); 15 | void debug_print_bounds(lprec *lp, REAL *upbo, REAL *lowbo); 16 | void blockWriteLREAL(FILE *output, char *label, LREAL *vector, int first, int last); 17 | void blockWriteAMAT(FILE *output, const char *label, lprec* lp, int first, int last); 18 | void blockWriteBMAT(FILE *output, const char *label, lprec* lp, int first, int last); 19 | 20 | 21 | /* Model reporting headers */ 22 | void REPORT_objective(lprec *lp); 23 | void REPORT_solution(lprec *lp, int columns); 24 | void REPORT_constraints(lprec *lp, int columns); 25 | void REPORT_duals(lprec *lp); 26 | void REPORT_extended(lprec *lp); 27 | 28 | /* Other rarely used, but sometimes extremely useful reports */ 29 | void REPORT_constraintinfo(lprec *lp, char *datainfo); 30 | void REPORT_modelinfo(lprec *lp, MYBOOL doName, char *datainfo); 31 | void REPORT_lp(lprec *lp); 32 | MYBOOL REPORT_tableau(lprec *lp); 33 | void REPORT_scales(lprec *lp); 34 | MYBOOL REPORT_debugdump(lprec *lp, char *filename, MYBOOL livedata); 35 | MYBOOL REPORT_mat_mmsave(lprec *lp, char *filename, int *colndx, MYBOOL includeOF, char *infotext); 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif 40 | 41 | #endif /* HEADER_lp_report */ 42 | 43 | -------------------------------------------------------------------------------- /RFM/sources/src/lp_scale.h: -------------------------------------------------------------------------------- 1 | #ifndef HEADER_lp_scale 2 | #define HEADER_lp_scale 3 | 4 | #include "lp_types.h" 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | 10 | /* Put function headers here */ 11 | STATIC MYBOOL scale_updatecolumns(lprec *lp, REAL *scalechange, MYBOOL updateonly); 12 | STATIC MYBOOL scale_updaterows(lprec *lp, REAL *scalechange, MYBOOL updateonly); 13 | STATIC MYBOOL scale_rows(lprec *lp, REAL *scaledelta); 14 | STATIC MYBOOL scale_columns(lprec *lp, REAL *scaledelta); 15 | STATIC void unscale_columns(lprec *lp); 16 | STATIC REAL scale(lprec *lp, REAL *scaledelta); 17 | STATIC REAL scaled_mat(lprec *lp, REAL value, int rownr, int colnr); 18 | STATIC REAL unscaled_mat(lprec *lp, REAL value, int rownr, int colnr); 19 | STATIC REAL scaled_value(lprec *lp, REAL value, int index); 20 | STATIC REAL unscaled_value(lprec *lp, REAL value, int index); 21 | STATIC MYBOOL scaleCR(lprec *lp, REAL *scaledelta); 22 | STATIC MYBOOL finalize_scaling(lprec *lp, REAL *scaledelta); 23 | STATIC REAL auto_scale(lprec *lp); 24 | void undoscale(lprec *lp); 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | 30 | #endif /* HEADER_lp_scale */ 31 | 32 | -------------------------------------------------------------------------------- /RFM/sources/src/lp_simplex.h: -------------------------------------------------------------------------------- 1 | #ifndef HEADER_lp_simplex 2 | #define HEADER_lp_simplex 3 | 4 | #include "lp_types.h" 5 | 6 | #define ForceDualSimplexInBB /* Force use/switch of dual simplex in B&B */ 7 | #define AssumeHighAccuracyInBB /* No iteration of simplex solves at infeasibility */ 8 | /*#define UseLongStepPruning*/ 9 | /*#define UseLongStepDualPhase1*/ 10 | #define primal_UseRejectionList 11 | #define dual_UseRejectionList 12 | #define dual_RemoveBasicFixedVars 13 | /*#define dual_Phase1PriceEqualities */ /* Force elimination of equality slacks */ 14 | #define AcceptMarginalAccuracy 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif 19 | 20 | /* Put function headers here */ 21 | STATIC int primloop(lprec *lp, MYBOOL primalfeasible, REAL primaloffset); 22 | STATIC int dualloop(lprec *lp, MYBOOL dualfeasible, int dualinfeasibles[], REAL dualoffset); 23 | STATIC int spx_run(lprec *lp, MYBOOL validInvB); 24 | STATIC int spx_solve(lprec *lp); 25 | STATIC int lag_solve(lprec *lp, REAL start_bound, int num_iter); 26 | STATIC int heuristics(lprec *lp, int mode); 27 | STATIC int lin_solve(lprec *lp); 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | 33 | #endif /* HEADER_lp_simplex */ 34 | 35 | -------------------------------------------------------------------------------- /RFM/sources/src/lp_wlp.h: -------------------------------------------------------------------------------- 1 | #ifndef HEADER_lp_lp 2 | #define HEADER_lp_lp 3 | 4 | #include "lp_types.h" 5 | 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | /* Put function headers here */ 12 | MYBOOL LP_writefile(lprec *lp, char *filename); 13 | MYBOOL LP_writehandle(lprec *lp, FILE *output); 14 | 15 | 16 | #ifdef __cplusplus 17 | } 18 | #endif 19 | 20 | #endif /* HEADER_lp_lp */ 21 | 22 | -------------------------------------------------------------------------------- /RFM/sources/src/lpkit.h: -------------------------------------------------------------------------------- 1 | #include "lp_lib.h" 2 | #include "lp_report.h" 3 | 4 | #define MALLOC(ptr, nr, type)\ 5 | ((((nr) == 0) || ((ptr = (type *) malloc((size_t)((nr) * sizeof(*ptr)))) == NULL)) ? \ 6 | report(NULL, CRITICAL, "malloc of %d bytes failed on line %d of file %s\n",\ 7 | (nr) * sizeof(*ptr), __LINE__, __FILE__), (ptr = NULL /* (void *) 0 */) : \ 8 | ptr\ 9 | ) 10 | 11 | #define CALLOC(ptr, nr, type)\ 12 | ((((nr) == 0) || ((ptr = (type *) calloc((size_t)(nr), sizeof(*ptr))) == NULL)) ? \ 13 | report(NULL, CRITICAL, "calloc of %d bytes failed on line %d of file %s\n",\ 14 | (nr) * sizeof(*ptr), __LINE__, __FILE__), (ptr = NULL /* (void *) 0 */) : \ 15 | ptr\ 16 | ) 17 | 18 | #define REALLOC(ptr, nr, type)\ 19 | ((((nr) == 0) || ((ptr = (type *) realloc(ptr, (size_t)((nr) * sizeof(*ptr)))) == NULL)) ? \ 20 | report(NULL, CRITICAL, "realloc of %d bytes failed on line %d of file %s\n",\ 21 | (nr) * sizeof(*ptr), __LINE__, __FILE__), (ptr = NULL /* (void *) 0 */) : \ 22 | ptr\ 23 | ) 24 | 25 | #if defined FREE 26 | # undef FREE 27 | #endif 28 | 29 | #define FREE(ptr) if (ptr != NULL) {free(ptr), ptr = NULL;} else 30 | 31 | #define MALLOCCPY(nptr, optr, nr, type)\ 32 | (MALLOC(nptr, nr, type), (nptr != NULL) ? memcpy(nptr, optr, (size_t)((nr) * sizeof(*optr))) : 0, nptr) 33 | -------------------------------------------------------------------------------- /RFM/sources/src/lpsolve.h: -------------------------------------------------------------------------------- 1 | // stdafx.h : include file for standard system include files, 2 | // or project specific include files that are used frequently, but 3 | // are changed infrequently 4 | // 5 | 6 | #if !defined(AFX_STDAFX_H__22BF6D92_917F_4BDF_B806_0954721EBA95__INCLUDED_) 7 | #define AFX_STDAFX_H__22BF6D92_917F_4BDF_B806_0954721EBA95__INCLUDED_ 8 | 9 | #if _MSC_VER > 1000 10 | #pragma once 11 | #endif // _MSC_VER > 1000 12 | 13 | 14 | // Insert your headers here 15 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 16 | 17 | #include 18 | 19 | // TODO: reference additional headers your program requires here 20 | 21 | //{{AFX_INSERT_LOCATION}} 22 | // Microsoft Visual C++ will insert additional declarations immediately before the previous line. 23 | 24 | #endif // !defined(AFX_STDAFX_H__22BF6D92_917F_4BDF_B806_0954721EBA95__INCLUDED_) 25 | -------------------------------------------------------------------------------- /RFM/sources/src/lusolio.h: -------------------------------------------------------------------------------- 1 | #ifndef HEADER_lusolio 2 | #define HEADER_lusolio 3 | 4 | /* Include necessary libraries */ 5 | /* ------------------------------------------------------------------------- */ 6 | #include "lusol.h" 7 | 8 | MYBOOL ctf_read_A(char *filename, int maxm, int maxn, int maxnz, 9 | int *m, int *n, int *nnzero, int *iA, int *jA, REAL *Aij); 10 | MYBOOL ctf_size_A(char *filename, int *m, int *n, int *nnzero); 11 | MYBOOL ctf_read_b(char *filename, int m, REAL *b); 12 | 13 | MYBOOL mmf_read_A(char *filename, int maxM, int maxN, int maxnz, 14 | int *M, int *N, int *nz, int *iA, int *jA, REAL *Aij); 15 | MYBOOL mmf_size_A(char *filename, int *M, int *N, int *nz); 16 | MYBOOL mmf_read_b(char *filename, int m, REAL *b); 17 | 18 | MYBOOL hbf_read_A(char *filename, int maxM, int maxN, int maxnz, 19 | int *M, int *N, int *nz, int *iA, int *jA, REAL *Aij); 20 | MYBOOL hbf_size_A(char *filename, int *M, int *N, int *nz); 21 | MYBOOL hbf_read_b(char *filename, int m, REAL *b); 22 | 23 | 24 | #endif /* HEADER_lusolio */ 25 | -------------------------------------------------------------------------------- /RFM/sources/src/sparselib.h: -------------------------------------------------------------------------------- 1 | 2 | #include "commonlib.h" 3 | 4 | /*#define DEBUG_SPARSELIB*/ 5 | 6 | #define INITIALSIZE 10 7 | #define RESIZEDELTA 4 8 | 9 | #ifndef SPARSELIB 10 | 11 | #define SPARSELIB 12 | 13 | typedef struct _sparseVector { 14 | int limit; 15 | int size; 16 | int count; 17 | int *index; 18 | REAL *value; 19 | } sparseVector; 20 | 21 | typedef struct _sparseMatrix { 22 | int limit; 23 | int size; 24 | int count; 25 | int limitVector; 26 | sparseVector **list; 27 | } sparseMatrix; 28 | 29 | #endif 30 | 31 | 32 | #ifdef __cplusplus 33 | extern "C" { 34 | #endif 35 | 36 | sparseMatrix *createMatrix(int dimLimit, int lenLimit, int initVectors); 37 | void resizeMatrix(sparseMatrix *matrix, int newSize); 38 | int appendMatrix(sparseMatrix *matrix, sparseVector *newVector); 39 | int NZcountMatrix(sparseMatrix *matrix); 40 | void freeMatrix(sparseMatrix *matrix); 41 | void printMatrix(int n, sparseMatrix *matrix, int modulo, MYBOOL showEmpty); 42 | 43 | sparseVector *createVector(int dimLimit, int initSize); 44 | sparseVector *cloneVector(sparseVector *sparse); 45 | int redimensionVector(sparseVector *sparse, int newDim); 46 | int resizeVector(sparseVector *sparse, int newSize); 47 | void moveVector(sparseVector *sparse, int destPos, int sourcePos, int itemCount); 48 | void rotateVector(sparseVector *sparse, int startPos, int chainSize, int stepDelta); 49 | void swapVector(sparseVector *sparse1, sparseVector *sparse2); 50 | void freeVector(sparseVector *sparse); 51 | void printVector(int n, sparseVector *sparse, int modulo); 52 | MYBOOL verifyVector(sparseVector *sparse); 53 | 54 | int firstIndex(sparseVector *sparse); 55 | int lastIndex(sparseVector *sparse); 56 | int getDiagonalIndex(sparseVector *sparse); 57 | int putDiagonalIndex(sparseVector *sparse, int index); 58 | MYBOOL putDiagonal(sparseVector *sparse, REAL value); 59 | REAL getDiagonal(sparseVector *sparse); 60 | REAL getItem(sparseVector *sparse, int targetIndex); 61 | REAL putItem(sparseVector *sparse, int targetIndex, REAL value); 62 | REAL addtoItem(sparseVector *sparse, int targetIndex, REAL value); 63 | void swapItems(sparseVector *sparse, int firstIndex, int secondIndex); 64 | void clearVector(sparseVector *sparse, int indexStart, int indexEnd); 65 | int getVector(sparseVector *sparse, REAL *dense, int indexStart, int indexEnd, MYBOOL doClear); 66 | void putVector(sparseVector *sparse, REAL *dense, int indexStart, int indexEnd); 67 | void fillVector(sparseVector *sparse, int count, REAL value); 68 | 69 | REAL dotVector(sparseVector *sparse, REAL *dense, int indexStart, int indexEnd); 70 | 71 | void daxpyVector1(sparseVector *sparse, REAL scalar, REAL *dense, int indexStart, int indexEnd); 72 | void daxpyVector2(REAL *dense, REAL scalar, sparseVector *sparse, int indexStart, int indexEnd); 73 | void daxpyVector3(sparseVector *sparse1, REAL scalar, sparseVector *sparse2, int indexStart, int indexEnd); 74 | 75 | void dswapVector1(sparseVector *sparse, REAL *dense, int indexStart, int indexEnd); 76 | void dswapVector2(REAL *dense, sparseVector *sparse, int indexStart, int indexEnd); 77 | void dswapVector3(sparseVector *sparse1, sparseVector *sparse2, int indexStart, int indexEnd); 78 | 79 | int idamaxVector(sparseVector *sparse, int is, REAL *maxValue); 80 | 81 | #ifdef __cplusplus 82 | } 83 | #endif 84 | 85 | -------------------------------------------------------------------------------- /RFM/sources/src/ufortify.h: -------------------------------------------------------------------------------- 1 | /* 2 | * FILE: 3 | * ufortify.h 4 | * 5 | * DESCRIPTION: 6 | * User options for fortify. Changes to this file require fortify.c to be 7 | * recompiled, but nothing else. 8 | */ 9 | 10 | #ifndef __UFORTIFY_H__ 11 | #define __UFORTIFY_H__ 12 | 13 | #define FORTIFY_STORAGE 14 | 15 | #if defined MSDOS || defined __BORLANDC__ || defined __HIGHC__ 16 | # define KNOWS_POINTER_TYPE 17 | #endif 18 | 19 | #define FORTIFY_WAIT_FOR_KEY /* Pause after message */ 20 | 21 | #if !defined FORTIFY_BEFORE_SIZE 22 | # define FORTIFY_BEFORE_SIZE 16 /* Bytes to allocate before block */ 23 | #endif 24 | 25 | #if !defined FORTIFY_BEFORE_VALUE 26 | # define FORTIFY_BEFORE_VALUE 0xA3 /* Fill value before block */ 27 | #endif 28 | 29 | #if !defined FORTIFY_AFTER_SIZE 30 | # define FORTIFY_AFTER_SIZE 16 /* Bytes to allocate after block */ 31 | #endif 32 | 33 | #if !defined FORTIFY_AFTER_VALUE 34 | # define FORTIFY_AFTER_VALUE 0xA5 /* Fill value after block */ 35 | #endif 36 | 37 | #define FILL_ON_MALLOC /* Nuke out malloc'd memory */ 38 | 39 | #if !defined FILL_ON_MALLOC_VALUE 40 | # define FILL_ON_MALLOC_VALUE 0xA7 /* Value to initialize with */ 41 | #endif 42 | 43 | #define FILL_ON_FREE /* free'd memory is cleared */ 44 | 45 | #if !defined FILL_ON_FREE_VALUE 46 | # define FILL_ON_FREE_VALUE 0xA9 /* Value to de-initialize with */ 47 | #endif 48 | 49 | #define FORTIFY_CheckInterval 1 /* seconds */ 50 | /* #define CHECK_ALL_MEMORY_ON_MALLOC */ 51 | #define CHECK_ALL_MEMORY_ON_FREE 52 | #define PARANOID_FREE 53 | 54 | #define WARN_ON_MALLOC_FAIL /* A debug is issued on a failed malloc */ 55 | #define WARN_ON_ZERO_MALLOC /* A debug is issued on a malloc(0) */ 56 | #define WARN_ON_FALSE_FAIL /* See Fortify_SetMallocFailRate */ 57 | #define WARN_ON_SIZE_T_OVERFLOW/* Watch for breaking the 64K limit in */ 58 | /* some braindead architectures... */ 59 | 60 | #define FORTIFY_LOCK() 61 | #define FORTIFY_UNLOCK() 62 | 63 | #endif 64 | -------------------------------------------------------------------------------- /RFM/sources/src/wrapper.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "fuzzymeasuretools.h" 3 | #include "fuzzymeasurefit.h" 4 | extern "C" { 5 | 6 | void fittingCall(int *n, int* datanum,int* Kadd, double *v, double *Dataset) 7 | { 8 | double orness[2]; 9 | orness[0]=0; 10 | orness[1]=1; 11 | int res; 12 | int nn = *n; 13 | unsigned int m; 14 | int datanums = *datanum; 15 | int additive = *Kadd; 16 | 17 | Preparations_FM(nn,&m); 18 | 19 | double *w=new double[m]; 20 | 21 | res = FuzzyMeasureFitLP(nn, m, datanums, additive, w, Dataset, 0, NULL , NULL, 0, orness); 22 | 23 | for(int i=0; i $exp_dir/all_scores.txt 8 | 9 | python3 bin/util/format_result_table.py $exp_dir/all_scores.txt > $exp_dir/dendrogram_purity.tex 10 | 11 | cat $exp_dir/dendrogram_purity.tex 12 | 13 | echo "Dendrogram Purity Result table saved here: $exp_dir/dendrogram_purity.tex" -------------------------------------------------------------------------------- /StreaKHC/bin/util/format_result_table.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | import sys 3 | 4 | 5 | def load_result_file(fn): 6 | """ 7 | Result file format: 8 | algorithm dataset dendrogram purity 9 | 10 | Args: 11 | fn: filename 12 | 13 | Returns: dictionary: alg -> dataset -> (mean(dp),std(dp) 14 | 15 | """ 16 | alg2dataset2score = {} 17 | alg2mean = {} 18 | with open(fn, 'r') as fin: 19 | for line in fin: 20 | try: 21 | splt = line.strip().split("\t") 22 | dataset, alg, dp = splt[:3] 23 | if alg not in alg2dataset2score: 24 | alg2dataset2score[alg] = {} 25 | alg2mean[alg] = {} 26 | if dataset not in alg2dataset2score[alg]: 27 | alg2dataset2score[alg][dataset] = [] 28 | alg2dataset2score[alg][dataset].append(float(dp)) 29 | except: 30 | pass 31 | for alg in alg2dataset2score: 32 | mean_score = np.mean([alg2dataset2score[alg][data] 33 | for data in alg2dataset2score[alg]]) 34 | alg2mean[alg]["_mean_score"] = mean_score 35 | 36 | for alg in alg2dataset2score: 37 | for dataset in alg2dataset2score[alg]: 38 | mean = np.mean(alg2dataset2score[alg][dataset]) 39 | std = np.std(alg2dataset2score[alg][dataset]) 40 | alg2dataset2score[alg][dataset] = (mean, std) 41 | return (alg2dataset2score, alg2mean) 42 | 43 | 44 | def escape_latex(s): 45 | s = s.replace("_", "\\_") 46 | return s 47 | 48 | 49 | def latex_table(alg_score): 50 | table_string = """\\begin{table}\n\\centering\n\\caption{some caption}\n\\begin{tabular}""" 51 | # num_ds = max([len(alg2dataset2score[x]) for x in alg2dataset2score]) 52 | alg2dataset2score = alg_score[0] 53 | alg2mean = alg_score[1] 54 | num_al = len(alg2dataset2score) 55 | formatting = "{c" + "c" * num_al + "}" 56 | table_string += format(formatting) 57 | table_string += "\n\\toprule\n" 58 | alg_names = alg2dataset2score.keys() 59 | 60 | ds_names = list( 61 | set([name for x in alg2dataset2score for name in alg2dataset2score[x]])) 62 | table_string += "\\bf Dataset & \\bf " + \ 63 | " & \\bf ".join(escape_latex(x) for x in alg_names) 64 | table_string += " \\\\ \midrule\n" 65 | ds_names = sorted(ds_names) 66 | socre_mean = [alg2mean[alg]["_mean_score"] for alg in alg_names] 67 | for ds in ds_names: 68 | scores = ["%.2f $\\pm$ %.2f" % (alg2dataset2score[alg][ds][0], alg2dataset2score[alg][ds][1]) 69 | if ds in alg2dataset2score[alg] else "-" for alg in alg_names] 70 | table_string += "%s & %s \\\\\n" % (ds, " & ".join(scores)) 71 | table_string += "\midrule\n" 72 | table_string += "bf Mean & " + \ 73 | " & ".join("{:.2f}".format(x) for x in socre_mean) 74 | table_string += " \\\\ \\bottomrule\n\\end{tabular}\n\\end{table}" 75 | return table_string 76 | 77 | 78 | if __name__ == "__main__": 79 | print(latex_table(load_result_file(sys.argv[1]))) 80 | -------------------------------------------------------------------------------- /StreaKHC/bin/util/process_covtype.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import numpy as np 3 | 4 | if __name__ == "__main__": 5 | input_file = sys.argv[1] 6 | output_file = sys.argv[2] 7 | dim=54 8 | id = 0 9 | with open(input_file,'r') as fin: 10 | with open(output_file,'w') as fout: 11 | for line in fin: 12 | splt = line.strip().split(",") 13 | fout.write(str(id)) 14 | fout.write(",") 15 | fout.write(str(splt[-1])) 16 | 17 | for item in splt[:-1]: 18 | fout.write(",") 19 | fout.write(str(item)) 20 | fout.write("\n") 21 | id += 1 22 | -------------------------------------------------------------------------------- /StreaKHC/bin/util/shuffle_dataset.sh: -------------------------------------------------------------------------------- 1 | set -exu 2 | 3 | dataset=$1 4 | num_shuffles=$2 5 | shuffle_data_path=$3 6 | 7 | mkdir -p $shuffle_data_path 8 | 9 | data_name=`basename $dataset` 10 | seed=40 11 | rseed=$seed 12 | pshuf() { perl -MList::Util=shuffle -e "srand($1); print shuffle(<>);" "$2"; } 13 | for i in `seq 1 $num_shuffles` 14 | do 15 | shuffled_data="${shuffle_data_path}/${data_name%%.*}_${i}.${data_name#*.}" 16 | if ! [ -f $shuffled_data ]; then 17 | echo "Shuffling $dataset > $shuffled_data" 18 | pshuf $rseed $dataset > $shuffled_data 19 | fi 20 | rseed=$((seed + i)) 21 | done -------------------------------------------------------------------------------- /StreaKHC/data/raw/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulip-lab/open-code/afcc27a3cabf9b5658309b84a9940c8533a397ca/StreaKHC/data/raw/.gitkeep -------------------------------------------------------------------------------- /StreaKHC/data/raw/wine.csv: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:8be2a340b124b62c42bb6c31908cd0fc134591077b474dfc2595ef8de0344259 3 | size 25890 4 | -------------------------------------------------------------------------------- /StreaKHC/data/runned/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tulip-lab/open-code/afcc27a3cabf9b5658309b84a9940c8533a397ca/StreaKHC/data/runned/.gitkeep -------------------------------------------------------------------------------- /StreaKHC/data/runned/ALLAML.csv: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:d5a39d25a9cc0dc9f473fcc602346d05943c8371b25ff39848e2d3d12838c8f6 3 | size 5514722 4 | -------------------------------------------------------------------------------- /StreaKHC/data/runned/Isolet.csv: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:4631656058ce453d32d83cb2f4274c7e66aca6658357c92deaee6244fdcc3f38 3 | size 9158594 4 | -------------------------------------------------------------------------------- /StreaKHC/data/runned/LSVT.csv: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:81bc95a059b1c042e056256d000b075112dee7b7e94fba14df4abc43d18e98db 3 | size 445232 4 | -------------------------------------------------------------------------------- /StreaKHC/data/runned/LandCover.csv: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:91a278793fe6f1f1a1144ddbaec1bab6aeb031e0611f8bafa47413e2b64eb19b 3 | size 1093481 4 | -------------------------------------------------------------------------------- /StreaKHC/data/runned/Segment.csv: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:2a815a1a05f9398ac300b3519d8e2964a99a0f35c731740e20dec1a9d6df56a1 3 | size 448567 4 | -------------------------------------------------------------------------------- /StreaKHC/data/runned/Synthetic.csv: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:69dd3ed1ecb393ec1b0bd24b297d21369439065a15f78c49294e00179bc09848 3 | size 41923 4 | -------------------------------------------------------------------------------- /StreaKHC/data/runned/WDBC.csv: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:ca44e3554916e0e30b93fc8022ce13b656a928c4680e41378849dba6c6d52882 3 | size 194252 4 | -------------------------------------------------------------------------------- /StreaKHC/data/runned/banknote.csv: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:da0a8def0c69275c966c4dc530e1d0ab2326ba8093682d8eda4e7698b2acaee2 3 | size 70301 4 | -------------------------------------------------------------------------------- /StreaKHC/data/runned/glass.tsv: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:bc4774ea56a98a0646b9fd5d038c1b066d1b7cda696151f07f3c5a1e79cadf41 3 | size 12329 4 | -------------------------------------------------------------------------------- /StreaKHC/data/runned/hill.csv: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:83f7b31b6e6ee4605eeec88d8c3aee2767e97f84489fe33af8ceea4981327d2a 3 | size 1527330 4 | -------------------------------------------------------------------------------- /StreaKHC/data/runned/lung.csv: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:579f9a0fd82853652bf2fad8358c87d2fbe828fc62984840b8c8d3ba76cb737b 3 | size 6956518 4 | -------------------------------------------------------------------------------- /StreaKHC/data/runned/musk.csv: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:11a63f7d503184738cafad6a34d557fda0287255102c76f6e2216a42867552a6 3 | size 858179 4 | -------------------------------------------------------------------------------- /StreaKHC/data/runned/pendig.csv: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:666099fe0a30e3ca52670156963c2762f1a2971d206424cd57b77e712d333779 3 | size 910608 4 | -------------------------------------------------------------------------------- /StreaKHC/data/runned/seeds.csv: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:17dc998ff0dcb31b2c03849245760eececc1ed19bee13270c575a3ed3dec14fa 3 | size 17154 4 | -------------------------------------------------------------------------------- /StreaKHC/data/runned/spam.csv: -------------------------------------------------------------------------------- 1 | version https://git-lfs.github.com/spec/v1 2 | oid sha256:86da567817d30d40c7567744c09ca9250d22c15a6f1a4c5bc85413a44bd49c1c 3 | size 1549768 4 | -------------------------------------------------------------------------------- /StreaKHC/src/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Xin Han 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -------------------------------------------------------------------------------- /StreaKHC/src/utils/__init__.py: -------------------------------------------------------------------------------- 1 | # Copyright 2021 hanxin 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -------------------------------------------------------------------------------- /StreaKHC/src/utils/file_utils.py: -------------------------------------------------------------------------------- 1 | # Copyright 2021 Xin Han 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # coding: utf-8 16 | 17 | import errno 18 | import os 19 | 20 | import numpy as np 21 | 22 | 23 | def mkdir_p_safe(dir): 24 | try: 25 | os.makedirs(dir) 26 | except OSError as exception: 27 | if exception.errno != errno.EEXIST: 28 | raise 29 | 30 | 31 | def remove_dirs(exp_dir_base, file_name): 32 | file_path = os.path.join(exp_dir_base, file_name) 33 | if os.path.exists(file_path): 34 | os.removedirs(file_path) 35 | 36 | 37 | def load_data(filename): 38 | if filename.endswith(".csv"): 39 | split_sep = "," 40 | elif filename.endswith(".tsv"): 41 | split_sep = '\t' 42 | with open(filename, 'r') as f: 43 | for line in f: 44 | splits = line.strip().split(sep=split_sep) 45 | pid, l, vec = splits[0], splits[1], np.array([float(x) 46 | for x in splits[2:]]) 47 | yield ((l, pid, vec)) -------------------------------------------------------------------------------- /StreaKHC/src/utils/logger.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | """ 3 | Copyright (c) 2021 Xin Han 4 | 5 | This Source Code Form is subject to the terms of the Mozilla Public 6 | License, v. 2.0. If a copy of the MPL was not distributed with this 7 | file, You can obtain one at http://mozilla.org/MPL/2.0/. 8 | """ 9 | # coding: utf-8 10 | 11 | import logging 12 | from logging import handlers 13 | 14 | 15 | class Logger(object): 16 | level_relations = { 17 | 'debug': logging.DEBUG, 18 | 'info': logging.INFO, 19 | 'warning': logging.WARNING, 20 | 'error': logging.ERROR, 21 | 'crit': logging.CRITICAL 22 | } 23 | 24 | def __init__(self, filename, 25 | level='info', 26 | when='D', 27 | backCount=25, 28 | fmt='%(asctime)s - %(pathname)s[line:%(lineno)d] - %(levelname)s: %(message)s'): 29 | self.logger = logging.getLogger(filename) 30 | format_str = logging.Formatter(fmt) 31 | self.logger.setLevel(self.level_relations.get(level)) 32 | console_handler = logging.StreamHandler() 33 | console_handler.setFormatter(format_str) 34 | file_handler = handlers.TimedRotatingFileHandler( 35 | filename=filename, when=when, backupCount=backCount, encoding='utf-8') 36 | file_handler.setFormatter(format_str) 37 | self.logger.addHandler(console_handler) 38 | self.logger.addHandler(file_handler) 39 | 40 | 41 | if __name__ == '__main__': 42 | log = Logger('all.log', level='debug') 43 | log.logger.debug('debug') 44 | log.logger.info('info') 45 | log.logger.warning('warning') 46 | log.logger.error('error') 47 | Logger('error.log', level='error').logger.error('error') 48 | --------------------------------------------------------------------------------