├── .gitattributes
├── src
├── All
│ ├── README.md
│ └── All.csproj
└── Association
│ ├── README.md
│ ├── Association.csproj
│ └── Apriori
│ ├── README.md
│ ├── CNode.cs
│ ├── DataFields.cs
│ ├── Apriori.cs
│ └── AssociationRule.cs
├── data
└── csv
│ └── small-market-basket.csv
├── README.md
├── test
├── Data_Test
│ ├── Data_Test.csproj
│ └── DataFields_Test.cs
└── Association
│ ├── Association_Test.csproj
│ └── Apriori_Test.cs
├── DataMining.sln
├── .gitignore
└── LICENSE
/.gitattributes:
--------------------------------------------------------------------------------
1 | # Auto detect text files and perform LF normalization
2 | * text=auto
3 |
--------------------------------------------------------------------------------
/src/All/README.md:
--------------------------------------------------------------------------------
1 | ## README
2 |
3 | This project is created to contains all other projects.
4 |
--------------------------------------------------------------------------------
/data/csv/small-market-basket.csv:
--------------------------------------------------------------------------------
1 | Bread,Milk,Chips,Mustard,Beer,Diaper,Eggs,Coke
2 | 1,1,1,1,0,0,0,0
3 | 1,0,1,1,1,1,1,0
4 | 0,1,0,0,1,1,0,1
5 | 1,1,0,0,1,1,0,0
6 | 1,1,1,0,0,1,0,1
7 | 1,1,0,1,1,1,0,0
8 | 1,1,0,0,0,1,0,1
--------------------------------------------------------------------------------
/src/Association/README.md:
--------------------------------------------------------------------------------
1 | ## README
2 |
3 | This project contains Association Mining Algorithms.
4 |
5 | ### Including Algorithms
6 |
7 | |Algorithm|Code|Documentation|
8 | |---|---|---|
9 | |**Apriori**|[Apriori](https://github.com/cotur/DataMining/tree/master/src/Association/Apriori)|[Documentation](https://github.com/cotur/DataMining/tree/master/src/Association/Apriori/README.md)|
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 |
2 | # DataMining
3 |
4 | Some DataMining Algorithms based on C#
5 |
6 | ### Depencies
7 | ```
8 | none
9 | ```
10 |
11 | ### Installing
12 |
13 |
14 | NuGet Package That Includes All Algorithms: https://www.nuget.org/packages/Cotur.DataMining/
15 |
16 | You can dowload algorithms individually.
17 |
18 | ### Existing Algorithms
19 |
20 | |Algorithm|NuGet|Info|
21 | |---|---|---|
22 | |[Association Rules](https://github.com/cotur/DataMining/tree/master/src/Association)|[Cotur.DataMining.Association](https://www.nuget.org/packages/Cotur.DataMining.Association)|[Documentation](https://github.com/cotur/DataMining/tree/master/src/Association/README.md)|
--------------------------------------------------------------------------------
/test/Data_Test/Data_Test.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp3.1
5 |
6 | false
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/test/Association/Association_Test.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netcoreapp3.1
5 |
6 | false
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/src/Association/Association.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.0
5 | Cotur.DataMining.Association
6 | 1.2.0
7 | cotur
8 | Datamining
9 | Association Mining Algorithms
10 | - Apriori
11 | LICENSE
12 | https://github.com/cotur/DataMining
13 | git
14 | DataMining Apriori MachineLearning Algorithm
15 |
16 | true
17 |
18 |
19 |
20 |
21 | True
22 |
23 |
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/src/All/All.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | netstandard2.0
5 | Cotur.DataMining
6 | 1.2.0
7 | cotur
8 | Datamining
9 |
10 | DataMining Algorithms
11 |
12 | Existing Algorithms
13 | - Apriori
14 |
15 | LICENSE
16 | https://github.com/cotur/DataMining
17 | git
18 | DataMining MachineLearning Algorithm Apriori
19 |
20 | true
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 | True
30 |
31 |
32 |
33 |
34 |
--------------------------------------------------------------------------------
/test/Data_Test/DataFields_Test.cs:
--------------------------------------------------------------------------------
1 | using Cotur.DataMining.Association;
2 | using Shouldly;
3 | using System.Collections.Generic;
4 | using Xunit;
5 |
6 | namespace Data_Test
7 | {
8 | public class DataFields_Test
9 | {
10 | [Fact]
11 | public void FieldNameGeneration()
12 | {
13 | var transaction1 = new List() { 0, 1, 2, 3 };
14 | var transaction2 = new List() { 0, 2, 3, 4, 5, 6 };
15 | var transaction3 = new List() { 1, 4, 5, 7 };
16 | var transaction4 = new List() { 0, 1, 4, 5 };
17 | var transaction5 = new List() { 0, 1, 2, 5, 7 };
18 | var transaction6 = new List() { 0, 1, 3, 4, 5 };
19 | var transaction7 = new List() { 0, 1, 5, 7 };
20 |
21 | var transactions = new List>()
22 | {
23 | transaction1,
24 | transaction2,
25 | transaction3,
26 | transaction4,
27 | transaction5,
28 | transaction6,
29 | transaction7
30 | };
31 |
32 | var data = new DataFields(transactions);
33 |
34 | data.FieldNames.Count.ShouldBe(8);
35 | }
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/Association/Apriori/README.md:
--------------------------------------------------------------------------------
1 | ## Apriori Algorithm
2 |
3 | ### Usage
4 |
5 | Example Dataset
6 |
7 | ```
8 | fieldNames => Bread,Milk,Chips,Mustard,Beer,Diaper,Eggs,Coke
9 | transaction 1# => 1,1,1,1,0,0,0,0
10 | transaction 2# => 1,0,1,1,1,1,1,0
11 | transaction 3# => 0,1,0,0,1,1,0,1
12 | transaction 4# => 1,1,0,0,1,1,0,0
13 | transaction 5# => 1,1,1,0,0,1,0,1
14 | transaction 6# => 1,1,0,1,1,1,0,0
15 | transaction 7# => 1,1,0,0,0,1,0,1
16 | ```
17 |
18 | Create DataFields object that contains your data.
19 | ```csharp
20 | List Names; // FieldNames
21 | List Rows; // your data
22 | DataFields data = new DataFields(Names, Rows);
23 | Apriori myApriori = new Apriori(data);
24 | ```
25 | or just with Data
26 | ```csharp
27 | List Rows; // your data
28 | DataFields data = new DataFields(Rows);
29 | ```
30 | or
31 | ```csharp
32 | List transaction1 = new List(){ 0, 1, 2, 3 };
33 | List transaction2 = new List(){ 0, 2, 3, 4, 5, 6 };
34 | .
35 | .
36 | List transaction7 = new List(){ 0, 1, 5, 7 };
37 |
38 | List> Transactions = new List>()
39 | { transaction1, transaction2, .., transaction7 };
40 |
41 | DataFields data = new DataFields(maxColumn, Transactions);
42 | ```
43 | And calculations
44 | ```csharp
45 | Apriori myApriori = new Apriori(data);
46 | float minimumSupport = 0.4f; // 40% Minimum Support
47 |
48 | myApriori.CalculateCNodes(minimumSupport);
49 |
50 | myApriori.EachLevelOfNodes // Tables
51 | myApriori.Rules // All rules
52 | ```
53 |
--------------------------------------------------------------------------------
/DataMining.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.29728.190
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{15936E21-25FD-4243-A184-7DFF31E010BE}"
7 | EndProject
8 | Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{3D820FB0-3443-441F-A4A4-4E95A92C4D82}"
9 | EndProject
10 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Association_Test", "test\Association\Association_Test.csproj", "{53DE7678-F2FA-4017-86DF-CD4C8DBFDCA0}"
11 | EndProject
12 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Data_Test", "test\Data_Test\Data_Test.csproj", "{605999A1-14F6-4414-AA60-9470E2AF3C02}"
13 | EndProject
14 | Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Association", "src\Association\Association.csproj", "{0E171295-A98B-4718-9029-09A8D3E8962D}"
15 | EndProject
16 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "All", "src\All\All.csproj", "{B7E2BA6D-E1D8-46B3-8265-5AE89E22B142}"
17 | EndProject
18 | Global
19 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
20 | Debug|Any CPU = Debug|Any CPU
21 | Release|Any CPU = Release|Any CPU
22 | EndGlobalSection
23 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
24 | {53DE7678-F2FA-4017-86DF-CD4C8DBFDCA0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
25 | {53DE7678-F2FA-4017-86DF-CD4C8DBFDCA0}.Debug|Any CPU.Build.0 = Debug|Any CPU
26 | {53DE7678-F2FA-4017-86DF-CD4C8DBFDCA0}.Release|Any CPU.ActiveCfg = Release|Any CPU
27 | {53DE7678-F2FA-4017-86DF-CD4C8DBFDCA0}.Release|Any CPU.Build.0 = Release|Any CPU
28 | {605999A1-14F6-4414-AA60-9470E2AF3C02}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
29 | {605999A1-14F6-4414-AA60-9470E2AF3C02}.Debug|Any CPU.Build.0 = Debug|Any CPU
30 | {605999A1-14F6-4414-AA60-9470E2AF3C02}.Release|Any CPU.ActiveCfg = Release|Any CPU
31 | {605999A1-14F6-4414-AA60-9470E2AF3C02}.Release|Any CPU.Build.0 = Release|Any CPU
32 | {0E171295-A98B-4718-9029-09A8D3E8962D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
33 | {0E171295-A98B-4718-9029-09A8D3E8962D}.Debug|Any CPU.Build.0 = Debug|Any CPU
34 | {0E171295-A98B-4718-9029-09A8D3E8962D}.Release|Any CPU.ActiveCfg = Release|Any CPU
35 | {0E171295-A98B-4718-9029-09A8D3E8962D}.Release|Any CPU.Build.0 = Release|Any CPU
36 | {B7E2BA6D-E1D8-46B3-8265-5AE89E22B142}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
37 | {B7E2BA6D-E1D8-46B3-8265-5AE89E22B142}.Debug|Any CPU.Build.0 = Debug|Any CPU
38 | {B7E2BA6D-E1D8-46B3-8265-5AE89E22B142}.Release|Any CPU.ActiveCfg = Release|Any CPU
39 | {B7E2BA6D-E1D8-46B3-8265-5AE89E22B142}.Release|Any CPU.Build.0 = Release|Any CPU
40 | EndGlobalSection
41 | GlobalSection(SolutionProperties) = preSolution
42 | HideSolutionNode = FALSE
43 | EndGlobalSection
44 | GlobalSection(NestedProjects) = preSolution
45 | {53DE7678-F2FA-4017-86DF-CD4C8DBFDCA0} = {3D820FB0-3443-441F-A4A4-4E95A92C4D82}
46 | {605999A1-14F6-4414-AA60-9470E2AF3C02} = {3D820FB0-3443-441F-A4A4-4E95A92C4D82}
47 | {0E171295-A98B-4718-9029-09A8D3E8962D} = {15936E21-25FD-4243-A184-7DFF31E010BE}
48 | {B7E2BA6D-E1D8-46B3-8265-5AE89E22B142} = {15936E21-25FD-4243-A184-7DFF31E010BE}
49 | EndGlobalSection
50 | GlobalSection(ExtensibilityGlobals) = postSolution
51 | SolutionGuid = {DEFAE46E-CA5C-4E95-9FDB-DC1E63AAE751}
52 | EndGlobalSection
53 | EndGlobal
54 |
--------------------------------------------------------------------------------
/src/Association/Apriori/CNode.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Linq;
3 |
4 | namespace Cotur.DataMining.Association
5 | {
6 | public class CNode
7 | {
8 | public List ElementIDs { get; private set; }
9 | public float Support { get; private set; }
10 |
11 | private CNode()
12 | {
13 | ElementIDs = new List();
14 | Support = 0;
15 | }
16 |
17 | ///
18 | /// The Column Id of one element
19 | ///
20 | /// An integer that element's id
21 | public CNode(int elementId)
22 | {
23 | ElementIDs = new List(){ elementId };
24 | }
25 |
26 | ///
27 | /// The column ids of elements
28 | ///
29 | /// Integer IEnumerable that contains elements ids
30 | public CNode(IEnumerable elementIDs)
31 | {
32 | ElementIDs = elementIDs.ToList();
33 | }
34 |
35 | public CNode AddElement(int elementId)
36 | {
37 | ElementIDs.Add(elementId);
38 | return this;
39 | }
40 |
41 | public void CalculateSupport(List warehouse)
42 | {
43 | Support = 0;
44 | foreach (bool[] row in warehouse)
45 | {
46 | var confirmation = true;
47 | foreach (int id in ElementIDs)
48 | {
49 | if (row[id] == false)
50 | {
51 | confirmation = false;
52 | break;
53 | }
54 | }
55 |
56 | if (confirmation)
57 | {
58 | Support++;
59 | }
60 | }
61 |
62 | Support = (float)Support / (float)warehouse.Count;
63 | }
64 |
65 | public CNode FullCopyMe()
66 | {
67 | var newNode = new CNode();
68 | foreach (var item in ElementIDs)
69 | {
70 | newNode.ElementIDs.Add(item);
71 | }
72 |
73 | newNode.Support = Support;
74 | return newNode;
75 | }
76 |
77 | public string ToDetailedString(DataFields dataFields)
78 | {
79 | return string.Join(", ", dataFields.GetElementsName(ElementIDs));
80 | }
81 | }
82 |
83 | static class CNodeExtensions
84 | {
85 | public static IEnumerable, CNode>> GroupByElements(this IEnumerable nodes) =>
86 | nodes.GroupByElements(nodes.Min(node => node.ElementIDs.Count));
87 |
88 | public static IEnumerable, CNode>> GroupByElements(this IEnumerable nodes, int count) =>
89 | nodes.GroupBy(node => node.ElementIDs.Take(count), new SequenceCompare());
90 |
91 | private class SequenceCompare : IEqualityComparer>
92 | {
93 | public bool Equals(IEnumerable x, IEnumerable y) => x.SequenceEqual(y);
94 |
95 | public int GetHashCode(IEnumerable obj)
96 | {
97 | unchecked
98 | {
99 | var hash = 17;
100 | foreach (var i in obj)
101 | hash = hash * 23 + i.GetHashCode();
102 | return hash;
103 | }
104 | }
105 | }
106 | }
107 | }
--------------------------------------------------------------------------------
/src/Association/Apriori/DataFields.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.IO;
3 | using System.Linq;
4 |
5 | namespace Cotur.DataMining.Association
6 | {
7 | public class DataFields
8 | {
9 | public List FieldNames { get; private set; } = new List();
10 |
11 | public List Rows { get; private set; }
12 |
13 | public DataFields(IEnumerable fieldNames, IEnumerable> rows)
14 | {
15 | FieldNames = fieldNames.ToList();
16 | Rows = rows.Select(x => x.ToArray()).ToList();
17 | }
18 |
19 | public DataFields(IEnumerable> rows)
20 | {
21 | Rows = rows.Select(x => x.ToArray()).ToList();
22 | FillNames();
23 | }
24 |
25 | public DataFields(IEnumerable> transactions, IEnumerable fieldNames = null)
26 | {
27 | Implement(transactions.Max(x => x.Max()), transactions, fieldNames);
28 | }
29 |
30 | public DataFields(int fieldCount, IEnumerable> transactions, IEnumerable fieldNames = null)
31 | {
32 | Implement(fieldCount, transactions, fieldNames);
33 | }
34 |
35 | private void Implement(int fieldCount, IEnumerable> transactions, IEnumerable fieldNames = null)
36 | {
37 | Rows = new List();
38 | foreach (var transaction in transactions)
39 | {
40 | Rows.Add(CreateRow(fieldCount, transaction));
41 | }
42 |
43 | if (fieldNames == null)
44 | {
45 | FillNames();
46 | }
47 | else
48 | {
49 | FieldNames = fieldNames.ToList();
50 | }
51 | }
52 |
53 | private bool[] CreateRow(int size, IEnumerable idS)
54 | {
55 | var row = new bool[size + 1];
56 | foreach (int id in idS)
57 | {
58 | row[id] = true;
59 | }
60 | return row;
61 | }
62 |
63 | private void FillNames()
64 | {
65 | for (int i = 0; i < Rows.First().Length; i++)
66 | {
67 | FieldNames.Add("Column " + i);
68 | }
69 | }
70 |
71 | public List GetElementsName(List elementIDs)
72 | {
73 | return FieldNames.Where((e, i) => elementIDs.Contains(i)).ToList();
74 | }
75 |
76 | public static DataFields ReadFromCsv(string filePath, char splitWith = ',', bool headIsInfo = true, string acceptAsTrue = "1")
77 | {
78 | List fieldNames = null;
79 | List rows = new List();
80 |
81 | foreach (var line in File.ReadAllLines(filePath))
82 | {
83 | var splintedLine = line.Split(splitWith);
84 | if (headIsInfo)
85 | {
86 | fieldNames = splintedLine.Select(x => x.Trim()).ToList();
87 | headIsInfo = false;
88 | continue;
89 | }
90 |
91 | rows.Add(
92 | splintedLine.Select(x =>
93 | x.Trim() == acceptAsTrue
94 | ).ToArray()
95 | );
96 | }
97 |
98 | return fieldNames == null ? new DataFields(rows) : new DataFields(fieldNames, rows);
99 | }
100 | }
101 | }
102 |
--------------------------------------------------------------------------------
/test/Association/Apriori_Test.cs:
--------------------------------------------------------------------------------
1 | using Shouldly;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 | using Xunit;
5 | using Xunit.Abstractions;
6 |
7 | namespace Cotur.DataMining.Association
8 | {
9 | public class Apriori_Test
10 | {
11 | private readonly ITestOutputHelper _testOutputHelper;
12 |
13 | public Apriori_Test(ITestOutputHelper testOutputHelper)
14 | {
15 | _testOutputHelper = testOutputHelper;
16 | }
17 |
18 | [Fact]
19 | public void Apriori_One()
20 | {
21 | var transaction1 = new List() { 0, 1, 2, 3 };
22 | var transaction2 = new List() { 0, 2, 3, 4, 5, 6 };
23 | var transaction3 = new List() { 1, 4, 5, 7 };
24 | var transaction4 = new List() { 0, 1, 4, 5 };
25 | var transaction5 = new List() { 0, 1, 2, 5, 7 };
26 | var transaction6 = new List() { 0, 1, 3, 4, 5 };
27 | var transaction7 = new List() { 0, 1, 5, 7 };
28 |
29 | var transactions = new List>()
30 | {
31 | transaction1,
32 | transaction2,
33 | transaction3,
34 | transaction4,
35 | transaction5,
36 | transaction6,
37 | transaction7
38 | };
39 |
40 | var maxCol = transactions.Max(x => x.Max());
41 |
42 | var dataFields = new DataFields(maxCol, transactions);
43 |
44 | var myApriori = new Apriori(dataFields);
45 | var minimumSupport = 0.4f; // %40 Minimum Support
46 |
47 | myApriori.CalculateCNodes(minimumSupport);
48 |
49 | myApriori.Rules.ShouldNotBeNull();
50 | myApriori.Rules.Count.ShouldNotBe(0);
51 | myApriori.Rules.Count(x => x.Confidence >= .7f).ShouldBe(12);
52 |
53 | _testOutputHelper.WriteLine("Top rules ordered by Confidence (Up to 10)");
54 | foreach (var associationRule in myApriori.Rules.OrderByDescending(x => x.Confidence).Take(10))
55 | {
56 | _testOutputHelper.WriteLine(associationRule.ToDetailedString(dataFields));
57 | }
58 | }
59 |
60 | [Fact]
61 | public void Apriori_Market_Basket_One()
62 | {
63 | var dataFields = DataFields.ReadFromCsv(@"..\..\..\..\..\data\csv\small-market-basket.csv");
64 |
65 | var myApriori = new Apriori(dataFields);
66 |
67 | myApriori.CalculateCNodes(.4f);
68 |
69 | myApriori.Rules.ShouldNotBeNull();
70 | myApriori.Rules.Count.ShouldNotBe(0);
71 | myApriori.Rules.Count(x => x.Confidence >= .7f).ShouldBe(12);
72 |
73 | _testOutputHelper.WriteLine("Top rules ordered by Confidence (Up to 10)");
74 | foreach (var associationRule in myApriori.Rules.OrderByDescending(x => x.Confidence).Take(10))
75 | {
76 | _testOutputHelper.WriteLine(associationRule.ToDetailedString(dataFields));
77 | }
78 | }
79 |
80 | [Fact]
81 | public void Apriori_Big()
82 | {
83 | var csvFilePath = @"..\..\..\..\..\data\csv\big-text-1.csv";
84 |
85 | var dataFields = DataFields.ReadFromCsv(csvFilePath);
86 |
87 | var myApriori = new Apriori(dataFields);
88 |
89 | myApriori.CalculateCNodes(0.003f);
90 | myApriori.Rules.Count.ShouldBeGreaterThan(0);
91 |
92 | _testOutputHelper.WriteLine("Top rules ordered by Confidence (Up to 10)");
93 | foreach (var associationRule in myApriori.Rules.OrderByDescending(x => x.Confidence).Take(10))
94 | {
95 | _testOutputHelper.WriteLine(associationRule.ToDetailedString(dataFields));
96 | }
97 | }
98 | }
99 | }
100 |
--------------------------------------------------------------------------------
/src/Association/Apriori/Apriori.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Linq;
4 |
5 | namespace Cotur.DataMining.Association
6 | {
7 | public class Apriori
8 | {
9 | public DataFields Data { get; private set; }
10 | public List CNodes { get; private set; } = null;
11 | public List> EachLevelOfNodes { get; private set; } = new List>();
12 | public List Rules { get; private set; }
13 |
14 | public Apriori(DataFields data)
15 | {
16 | if (data == null)
17 | {
18 | throw new Exception("Apriori object can not be created with null DataFields");
19 | }
20 | Data = data;
21 | }
22 |
23 | public void CalculateCNodes(float minSupport)
24 | {
25 | if (minSupport <= 0)
26 | {
27 | throw new Exception("Minimum support should be bigged than 0");
28 | }
29 |
30 | CNodes = null;
31 | EachLevelOfNodes = new List>();
32 | Rules = null;
33 | _CalculateCNodes(minSupport);
34 | }
35 |
36 | private void _CalculateCNodes(float minSupport, List cNodes = null)
37 | {
38 | CNodes = cNodes ?? CNodes;
39 |
40 | if (CNodes == null)
41 | {
42 | FirstCNodes();
43 | }
44 |
45 | foreach (var node in CNodes)
46 | {
47 | node.CalculateSupport(Data.Rows);
48 | }
49 |
50 | CNodes.RemoveAll(node => node.Support < minSupport);
51 | EachLevelOfNodes.Add(CNodes);
52 |
53 | if (CNodes.Count > 1 && CalculateNextStep(minSupport))
54 | {
55 | _CalculateCNodes(minSupport, this.CNodes);
56 | }
57 |
58 | Rules = AssociationRule.GetLastLevelRules(EachLevelOfNodes);
59 | }
60 |
61 | private void FirstCNodes()
62 | {
63 | CNodes = new List();
64 | for (int i = 0; i < Data.Rows.First().Length; i++)
65 | {
66 | CNodes.Add(new CNode(i));
67 | }
68 | }
69 |
70 | private bool CalculateNextStep(float minSupport)
71 | {
72 | var tempList = new List();
73 |
74 | if (CNodes.First().ElementIDs.Count == 1)
75 | {
76 | for (var i = 0; i < CNodes.Count; i++)
77 | {
78 | for (var k = i + 1; k < CNodes.Count; k++)
79 | {
80 | var newNode = new CNode(CNodes[i].ElementIDs[0]);
81 | newNode.AddElement(CNodes[k].ElementIDs[0]);
82 | newNode.CalculateSupport(Data.Rows);
83 | tempList.Add(newNode);
84 | }
85 | }
86 | }
87 | else
88 | {
89 | foreach (var groups in CNodes.GroupByElements(CNodes.First().ElementIDs.Count - 1))
90 | {
91 | var groupsCount = groups.Count();
92 | for (var i = 0; i < groupsCount - 1; i++)
93 | {
94 | for (var k = i + 1; k < groupsCount; k++)
95 | {
96 | if (k == groupsCount)
97 | break;
98 |
99 | var newNode = groups.ElementAt(i).FullCopyMe();
100 | newNode.AddElement(groups.ElementAt(k).ElementIDs.Last());
101 | newNode.CalculateSupport(Data.Rows);
102 |
103 | if (newNode.Support >= minSupport)
104 | tempList.Add(newNode);
105 | }
106 | }
107 | }
108 | }
109 |
110 | if (tempList.Count >= 1)
111 | {
112 | //this.CNodes = CNode.ClearSame(tempList);// => this action deletes last cNode
113 | this.CNodes = tempList;
114 | return true;
115 | }
116 | return false;
117 | }
118 | }
119 | }
120 |
--------------------------------------------------------------------------------
/src/Association/Apriori/AssociationRule.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Linq;
3 |
4 | namespace Cotur.DataMining.Association
5 | {
6 | public class AssociationRule
7 | {
8 | public CNode NodeAB { get; private set; }
9 | public CNode NodeA { get; private set; }
10 | public CNode NodeB { get; private set; }
11 |
12 | public float Confidence { get; private set; }
13 | public float Lift { get; private set; }
14 | public float Conviction { get; private set; }
15 | public float Leverage { get; private set; }
16 | public float Coverage { get; private set; }
17 |
18 |
19 | public AssociationRule(CNode nodeAb, CNode nodeA, CNode nodeB)
20 | {
21 | NodeAB = nodeAb;
22 | NodeA = nodeA;
23 | NodeB = nodeB;
24 | }
25 |
26 | public AssociationRule Calculate()
27 | {
28 | CalculateConfidence();
29 | CalculateLift();
30 | CalculateConviction();
31 | CalculateLeverage();
32 | CalculateCoverage();
33 | return this;
34 | }
35 |
36 | private void CalculateConfidence()
37 | {
38 | Confidence = (float)NodeAB.Support / (float)NodeA.Support;
39 | }
40 |
41 | private void CalculateLift()
42 | {
43 | //this.Lift = (float)NodeAB.Support / ((float)NodeA.Support * (float)NodeB.Support);
44 | Lift = Confidence / NodeB.Support;
45 | }
46 |
47 | private void CalculateConviction()
48 | {
49 | Conviction = (1 - NodeB.Support) / (1 - Confidence);
50 | }
51 |
52 | private void CalculateLeverage()
53 | {
54 | Leverage = (float)NodeAB.Support - (float)(NodeA.Support * NodeB.Support);
55 | }
56 |
57 | private void CalculateCoverage()
58 | {
59 | Coverage = NodeA.Support;
60 | }
61 |
62 | private string GetCalculationsAsString()
63 | {
64 | return
65 | $"Confidence: {Confidence}, Lift: {Lift}, Conviction: {Conviction}, Leverage: {Leverage}, Coverage: {Coverage}";
66 | }
67 |
68 | public string ToDetailedString(DataFields dataFields)
69 | {
70 | return NodeA.ToDetailedString(dataFields) + " => " + NodeB.ToDetailedString(dataFields) + " || " + GetCalculationsAsString();
71 | }
72 |
73 | public static List GetAllRules(List> eachLevelOfCNodes)
74 | {
75 | var rules = new List();
76 |
77 | foreach (var cNodeLevel in eachLevelOfCNodes)
78 | {
79 | if (cNodeLevel.First().ElementIDs.Count <= 1)
80 | continue;
81 |
82 | foreach (var node in cNodeLevel)
83 | {
84 | rules.AddRange(GetRules(node, eachLevelOfCNodes));
85 | }
86 | }
87 |
88 | return rules;
89 | }
90 |
91 | private static List GetRules(CNode node, List> eachLevelOfCNodes)
92 | {
93 | var rules = new List();
94 | var subsets = SubSetsOf(node.ElementIDs).OrderBy(x => x.Count()).ToList();
95 |
96 | for (int i = 1; i < (subsets.Count / 2); i++)
97 | {
98 | var nodeA = new CNode(subsets[i].ToList());
99 | var nodeB = new CNode(subsets[subsets.Count - i - 1].ToList());
100 |
101 | var aFound = eachLevelOfCNodes[nodeA.ElementIDs.Count - 1].FirstOrDefault(x => x.ElementIDs.OrderBy(t => t).SequenceEqual(nodeA.ElementIDs.OrderBy(t => t)));
102 | var bFound = eachLevelOfCNodes[nodeB.ElementIDs.Count - 1].FirstOrDefault(x => x.ElementIDs.OrderBy(t => t).SequenceEqual(nodeB.ElementIDs.OrderBy(t => t)));
103 |
104 | if (aFound != null && bFound != null)
105 | {
106 | rules.Add(new AssociationRule(node, aFound, bFound).Calculate());
107 | rules.Add(new AssociationRule(node, bFound, aFound).Calculate());
108 | }
109 | }
110 |
111 | return rules;
112 | }
113 |
114 | public static List GetLastLevelRules(List> eachLevelOfCNodes)
115 | {
116 | var rules = new List();
117 |
118 |
119 | var cNodeLevel = eachLevelOfCNodes.Last();
120 |
121 | if (cNodeLevel.First().ElementIDs.Count <= 1)
122 | return rules;
123 |
124 | foreach (var node in cNodeLevel)
125 | {
126 | rules.AddRange(GetRules(node, eachLevelOfCNodes));
127 | }
128 |
129 | return rules;
130 | }
131 |
132 | private static IEnumerable> SubSetsOf(IEnumerable source)
133 | {
134 | if (!source.Any())
135 | return Enumerable.Repeat(Enumerable.Empty(), 1);
136 |
137 | var element = source.Take(1);
138 |
139 | var haveNots = SubSetsOf(source.Skip(1));
140 | var haves = haveNots.Select(set => element.Concat(set));
141 |
142 | return haves.Concat(haveNots);
143 | }
144 | }
145 | }
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 | ##
4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
5 |
6 | # Rider
7 |
8 | .idea/
9 |
10 | # User-specific files
11 | *.rsuser
12 | *.suo
13 | *.user
14 | *.userosscache
15 | *.sln.docstates
16 |
17 | # User-specific files (MonoDevelop/Xamarin Studio)
18 | *.userprefs
19 |
20 | # Mono auto generated files
21 | mono_crash.*
22 |
23 | # Build results
24 | [Dd]ebug/
25 | [Dd]ebugPublic/
26 | [Rr]elease/
27 | [Rr]eleases/
28 | x64/
29 | x86/
30 | [Aa][Rr][Mm]/
31 | [Aa][Rr][Mm]64/
32 | bld/
33 | [Bb]in/
34 | [Oo]bj/
35 | [Ll]og/
36 |
37 | # Visual Studio 2015/2017 cache/options directory
38 | .vs/
39 | # Uncomment if you have tasks that create the project's static files in wwwroot
40 | #wwwroot/
41 |
42 | # Visual Studio 2017 auto generated files
43 | Generated\ Files/
44 |
45 | # MSTest test Results
46 | [Tt]est[Rr]esult*/
47 | [Bb]uild[Ll]og.*
48 |
49 | # NUnit
50 | *.VisualState.xml
51 | TestResult.xml
52 | nunit-*.xml
53 |
54 | # Build Results of an ATL Project
55 | [Dd]ebugPS/
56 | [Rr]eleasePS/
57 | dlldata.c
58 |
59 | # Benchmark Results
60 | BenchmarkDotNet.Artifacts/
61 |
62 | # .NET Core
63 | project.lock.json
64 | project.fragment.lock.json
65 | artifacts/
66 |
67 | # StyleCop
68 | StyleCopReport.xml
69 |
70 | # Files built by Visual Studio
71 | *_i.c
72 | *_p.c
73 | *_h.h
74 | *.ilk
75 | *.meta
76 | *.obj
77 | *.iobj
78 | *.pch
79 | *.pdb
80 | *.ipdb
81 | *.pgc
82 | *.pgd
83 | *.rsp
84 | *.sbr
85 | *.tlb
86 | *.tli
87 | *.tlh
88 | *.tmp
89 | *.tmp_proj
90 | *_wpftmp.csproj
91 | *.log
92 | *.vspscc
93 | *.vssscc
94 | .builds
95 | *.pidb
96 | *.svclog
97 | *.scc
98 |
99 | # Chutzpah Test files
100 | _Chutzpah*
101 |
102 | # Visual C++ cache files
103 | ipch/
104 | *.aps
105 | *.ncb
106 | *.opendb
107 | *.opensdf
108 | *.sdf
109 | *.cachefile
110 | *.VC.db
111 | *.VC.VC.opendb
112 |
113 | # Visual Studio profiler
114 | *.psess
115 | *.vsp
116 | *.vspx
117 | *.sap
118 |
119 | # Visual Studio Trace Files
120 | *.e2e
121 |
122 | # TFS 2012 Local Workspace
123 | $tf/
124 |
125 | # Guidance Automation Toolkit
126 | *.gpState
127 |
128 | # ReSharper is a .NET coding add-in
129 | _ReSharper*/
130 | *.[Rr]e[Ss]harper
131 | *.DotSettings.user
132 |
133 | # JustCode is a .NET coding add-in
134 | .JustCode
135 |
136 | # TeamCity is a build add-in
137 | _TeamCity*
138 |
139 | # DotCover is a Code Coverage Tool
140 | *.dotCover
141 |
142 | # AxoCover is a Code Coverage Tool
143 | .axoCover/*
144 | !.axoCover/settings.json
145 |
146 | # Visual Studio code coverage results
147 | *.coverage
148 | *.coveragexml
149 |
150 | # NCrunch
151 | _NCrunch_*
152 | .*crunch*.local.xml
153 | nCrunchTemp_*
154 |
155 | # MightyMoose
156 | *.mm.*
157 | AutoTest.Net/
158 |
159 | # Web workbench (sass)
160 | .sass-cache/
161 |
162 | # Installshield output folder
163 | [Ee]xpress/
164 |
165 | # DocProject is a documentation generator add-in
166 | DocProject/buildhelp/
167 | DocProject/Help/*.HxT
168 | DocProject/Help/*.HxC
169 | DocProject/Help/*.hhc
170 | DocProject/Help/*.hhk
171 | DocProject/Help/*.hhp
172 | DocProject/Help/Html2
173 | DocProject/Help/html
174 |
175 | # Click-Once directory
176 | publish/
177 |
178 | # Publish Web Output
179 | *.[Pp]ublish.xml
180 | *.azurePubxml
181 | # Note: Comment the next line if you want to checkin your web deploy settings,
182 | # but database connection strings (with potential passwords) will be unencrypted
183 | *.pubxml
184 | *.publishproj
185 |
186 | # Microsoft Azure Web App publish settings. Comment the next line if you want to
187 | # checkin your Azure Web App publish settings, but sensitive information contained
188 | # in these scripts will be unencrypted
189 | PublishScripts/
190 |
191 | # NuGet Packages
192 | *.nupkg
193 | # NuGet Symbol Packages
194 | *.snupkg
195 | # The packages folder can be ignored because of Package Restore
196 | **/[Pp]ackages/*
197 | # except build/, which is used as an MSBuild target.
198 | !**/[Pp]ackages/build/
199 | # Uncomment if necessary however generally it will be regenerated when needed
200 | #!**/[Pp]ackages/repositories.config
201 | # NuGet v3's project.json files produces more ignorable files
202 | *.nuget.props
203 | *.nuget.targets
204 |
205 | # Microsoft Azure Build Output
206 | csx/
207 | *.build.csdef
208 |
209 | # Microsoft Azure Emulator
210 | ecf/
211 | rcf/
212 |
213 | # Windows Store app package directories and files
214 | AppPackages/
215 | BundleArtifacts/
216 | Package.StoreAssociation.xml
217 | _pkginfo.txt
218 | *.appx
219 | *.appxbundle
220 | *.appxupload
221 |
222 | # Visual Studio cache files
223 | # files ending in .cache can be ignored
224 | *.[Cc]ache
225 | # but keep track of directories ending in .cache
226 | !?*.[Cc]ache/
227 |
228 | # Others
229 | ClientBin/
230 | ~$*
231 | *~
232 | *.dbmdl
233 | *.dbproj.schemaview
234 | *.jfm
235 | *.pfx
236 | *.publishsettings
237 | orleans.codegen.cs
238 |
239 | # Including strong name files can present a security risk
240 | # (https://github.com/github/gitignore/pull/2483#issue-259490424)
241 | #*.snk
242 |
243 | # Since there are multiple workflows, uncomment next line to ignore bower_components
244 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622)
245 | #bower_components/
246 |
247 | # RIA/Silverlight projects
248 | Generated_Code/
249 |
250 | # Backup & report files from converting an old project file
251 | # to a newer Visual Studio version. Backup files are not needed,
252 | # because we have git ;-)
253 | _UpgradeReport_Files/
254 | Backup*/
255 | UpgradeLog*.XML
256 | UpgradeLog*.htm
257 | ServiceFabricBackup/
258 | *.rptproj.bak
259 |
260 | # SQL Server files
261 | *.mdf
262 | *.ldf
263 | *.ndf
264 |
265 | # Business Intelligence projects
266 | *.rdl.data
267 | *.bim.layout
268 | *.bim_*.settings
269 | *.rptproj.rsuser
270 | *- [Bb]ackup.rdl
271 | *- [Bb]ackup ([0-9]).rdl
272 | *- [Bb]ackup ([0-9][0-9]).rdl
273 |
274 | # Microsoft Fakes
275 | FakesAssemblies/
276 |
277 | # GhostDoc plugin setting file
278 | *.GhostDoc.xml
279 |
280 | # Node.js Tools for Visual Studio
281 | .ntvs_analysis.dat
282 | node_modules/
283 |
284 | # Visual Studio 6 build log
285 | *.plg
286 |
287 | # Visual Studio 6 workspace options file
288 | *.opt
289 |
290 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.)
291 | *.vbw
292 |
293 | # Visual Studio LightSwitch build output
294 | **/*.HTMLClient/GeneratedArtifacts
295 | **/*.DesktopClient/GeneratedArtifacts
296 | **/*.DesktopClient/ModelManifest.xml
297 | **/*.Server/GeneratedArtifacts
298 | **/*.Server/ModelManifest.xml
299 | _Pvt_Extensions
300 |
301 | # Paket dependency manager
302 | .paket/paket.exe
303 | paket-files/
304 |
305 | # FAKE - F# Make
306 | .fake/
307 |
308 | # CodeRush personal settings
309 | .cr/personal
310 |
311 | # Python Tools for Visual Studio (PTVS)
312 | __pycache__/
313 | *.pyc
314 |
315 | # Cake - Uncomment if you are using it
316 | # tools/**
317 | # !tools/packages.config
318 |
319 | # Tabs Studio
320 | *.tss
321 |
322 | # Telerik's JustMock configuration file
323 | *.jmconfig
324 |
325 | # BizTalk build output
326 | *.btp.cs
327 | *.btm.cs
328 | *.odx.cs
329 | *.xsd.cs
330 |
331 | # OpenCover UI analysis results
332 | OpenCover/
333 |
334 | # Azure Stream Analytics local run output
335 | ASALocalRun/
336 |
337 | # MSBuild Binary and Structured Log
338 | *.binlog
339 |
340 | # NVidia Nsight GPU debugger configuration file
341 | *.nvuser
342 |
343 | # MFractors (Xamarin productivity tool) working folder
344 | .mfractor/
345 |
346 | # Local History for Visual Studio
347 | .localhistory/
348 |
349 | # BeatPulse healthcheck temp database
350 | healthchecksdb
351 |
352 | # Backup folder for Package Reference Convert tool in Visual Studio 2017
353 | MigrationBackup/
354 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------