-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimdist.vb
More file actions
403 lines (379 loc) · 19.4 KB
/
Copy pathsimdist.vb
File metadata and controls
403 lines (379 loc) · 19.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
Imports System.Windows.Forms
'' Jaccard, Euclidiana e Bray-Curtis -
'' http://ecovirtual.ib.usp.br/doku.php?id=ecovirt:roteiro:comuni:comuni_classr&do=
'' http://prf.osu.cz/kbe/dokumenty/sw/ComEcoPaC/ComEcoPaC.pdf
'' Manhattan - http://cc.oulu.fi/~jarioksa/softhelp/vegan/html/vegdist.html
'' Morisita -
'' http://cc.oulu.fi/~jarioksa/softhelp/vegan/html/dispindmorisita.html
'' http://www.zoology.ubc.ca/~krebs/downloads/krebs_chapter_12_2014.pdf
'' http://www.statisticshowto.com/morisita-index/
'' Morisita-Horn- https://en.wikipedia.org/wiki/Morisita%27s_overlap_index
'' Sorenson Similarity - C:\Users\WilliamCosta\Documents\DivEs - Documentação\ALS 5932_Lecture Richness and Diversity 10_08_08.pdf
'' Canberra - http://www.int-res.com/articles/meps/5/m005p125.pdf
'' Renkonen index - http://prf.osu.cz/kbe/dokumenty/sw/ComEcoPaC/ComEcoPaC.pdf
Public Class simdist
Private LibCalculate As New decalculate.calculate
' Private LibError As New deconfig.ErrorManager
Sub New()
Main()
End Sub
Public Function Jaccard(ByVal ODGV As DataGridView, ByVal iColumn1 As Integer, ByVal iColumn2 As Integer) As String
Dim lRow As Integer = ODGV.RowCount
Dim iR As Integer
Dim nSp1 As Integer, nSp2 As Integer, nSpCom As Integer
Dim sRTF As String = ""
Dim dJaccard As Double
Try
If Auditoria(ODGV) = False Then
If MsgAuditoria() = False Then
Return sRetAuditoria
Exit Function
End If
End If
For iR = 0 To lRow - 1
If ODGV.Rows(iR).Cells(iColumn1).Value > 0 Then
nSp1 += 1
End If
If ODGV.Rows(iR).Cells(iColumn2).Value > 0 Then
nSp2 += 1
End If
If ODGV.Rows(iR).Cells(iColumn1).Value > 0 And ODGV.Rows(iR).Cells(iColumn2).Value > 0 Then
nSpCom += 1
End If
Next
dJaccard = (nSpCom) / (nSp1 + nSp2 - nSpCom)
sRTF &= "<ul class='list-group'>"
sRTF &= "<li class='list-group-item'>Número de espécies da amostra " & ODGV.Columns(iColumn1).HeaderCell.Value & ": " & nSp1 & "</li>"
sRTF &= "<li class='list-group-item'>Número de espécies da amostra " & ODGV.Columns(iColumn2).HeaderCell.Value & ": " & nSp2 & "</li>"
sRTF &= "<li class='list-group-item'>Número de espécies em comum: " & nSpCom & "</li>"
sRTF &= "<li class='list-group-item'>Índice de Similaridade de Jaccard: " & Math.Round(dJaccard, 4) & "</li>"
sRTF &= "</ul>"
sResult = sHTMLStart & "<h3 class='alert alert-success'>Similaridade de Jaccard</h3>" & sRTF & sFooter & sHTMLEnd
Return sResult
Catch ex As Exception
LibError.ErrorView(ex)
Return retError(sHTMLStart, ex, sHTMLEnd)
End Try
End Function
Public Function Euclidiana(ByVal ODGV As DataGridView, ByVal iColumn1 As Integer, ByVal iColumn2 As Integer) As String
Dim lRow As Integer = ODGV.RowCount
Dim iR As Integer
Dim nSp1 As Integer, nSp2 As Integer, dn1n2 As Double
Dim sRTF As String = ""
Dim dEuclid As Double
Try
If Auditoria(ODGV) = False Then
If MsgAuditoria() = False Then
Return sRetAuditoria
Exit Function
End If
End If
For iR = 0 To lRow - 1
If ODGV.Rows(iR).Cells(iColumn1).Value > 0 Then
nSp1 += ODGV.Rows(iR).Cells(iColumn1).Value
End If
If ODGV.Rows(iR).Cells(iColumn2).Value > 0 Then
nSp2 += ODGV.Rows(iR).Cells(iColumn2).Value
End If
dn1n2 += (ODGV.Rows(iR).Cells(iColumn1).Value - ODGV.Rows(iR).Cells(iColumn2).Value) ^ 2
Next
dEuclid = Math.Sqrt(dn1n2)
sRTF &= "<ul class='list-group'>"
sRTF &= "<li class='list-group-item'>Número de indivíduos da amostra " & ODGV.Columns(iColumn1).HeaderCell.Value & ": " & nSp1 & "</li>"
sRTF &= "<li class='list-group-item'>Número de indivíduos da amostra " & ODGV.Columns(iColumn2).HeaderCell.Value & ": " & nSp2 & "</li>"
sRTF &= "<li class='list-group-item'>Distância Euclidiana: " & Math.Round(dEuclid, 4) & "</li>"
sRTF &= "</ul>"
sResult = sHTMLStart & "<h3 class='alert alert-success'>Distância Euclidiana</h3>" & sRTF & sFooter & sHTMLEnd
Return sResult
Catch ex As Exception
LibError.ErrorView(ex)
Return retError(sHTMLStart, ex, sHTMLEnd)
End Try
End Function
Public Function BCSim(ByVal ODGV As DataGridView, ByVal iColumn1 As Integer, ByVal iColumn2 As Integer) As String
Dim lRow As Integer = ODGV.RowCount
Dim iR As Integer, nSp1 As Integer, nSp2 As Integer
Dim iNum As Integer, dMin As Double, dSum As Double
Dim sRTF As String = ""
Dim dSimiliar As Double
Try
If Auditoria(ODGV) = False Then
If MsgAuditoria() = False Then
Return sRetAuditoria
Exit Function
End If
End If
For iR = 0 To lRow - 1
If ODGV.Rows(iR).Cells(iColumn1).Value > 0 Then
nSp1 += ODGV.Rows(iR).Cells(iColumn1).Value
iNum += ODGV.Rows(iR).Cells(iColumn1).Value
End If
If ODGV.Rows(iR).Cells(iColumn2).Value > 0 Then
nSp2 += ODGV.Rows(iR).Cells(iColumn2).Value
iNum += ODGV.Rows(iR).Cells(iColumn2).Value
End If
Next
For iR = 0 To lRow - 1
dMin = Math.Min(CByte(ODGV.Rows(iR).Cells(iColumn1).Value), CByte(ODGV.Rows(iR).Cells(iColumn2).Value))
dSum += dMin
Next
dSimiliar = (2 * dSum) / iNum
sRTF &= "<ul class='list-group'>"
sRTF &= "<li class='list-group-item'>Número de indivíduos da amostra " & ODGV.Columns(iColumn1).HeaderCell.Value & ": " & nSp1 & "</li>"
sRTF &= "<li class='list-group-item'>Número de indivíduos da amostra " & ODGV.Columns(iColumn2).HeaderCell.Value & ": " & nSp2 & "</li>"
sRTF &= "<li class='list-group-item'>Índice de Similaridade Bray-Curtis: " & Math.Round(dSimiliar, 4) & "</li>"
sRTF &= "<li class='list-group-item'>Índice de Disimilaridade Bray-Curtis: " & Math.Round(1 - dSimiliar, 4) & "</li>"
sRTF &= "</ul>"
sResult = sHTMLStart & "<h3 class='alert alert-success'>Similaridade de Bray-Curtis</h3>" & sRTF & sFooter & sHTMLEnd
Return sResult
Catch ex As Exception
LibError.ErrorView(ex)
Return retError(sHTMLStart, ex, sHTMLEnd)
End Try
End Function
Public Function BCDist(ByVal ODGV As DataGridView, ByVal iColumn1 As Integer, ByVal iColumn2 As Integer) As String
Dim lRow As Integer = ODGV.RowCount
Dim iR As Integer
Dim nSp1 As Integer, nSp2 As Integer, dn1n2 As Double
Dim sRTF As String = ""
Dim dDist As Double
Try
If Auditoria(ODGV) = False Then
If MsgAuditoria() = False Then
Return sRetAuditoria
Exit Function
End If
End If
For iR = 0 To lRow - 1
If ODGV.Rows(iR).Cells(iColumn1).Value > 0 Then
nSp1 += ODGV.Rows(iR).Cells(iColumn1).Value
End If
If ODGV.Rows(iR).Cells(iColumn2).Value > 0 Then
nSp2 += ODGV.Rows(iR).Cells(iColumn2).Value
End If
dn1n2 += Math.Abs(ODGV.Rows(iR).Cells(iColumn1).Value - ODGV.Rows(iR).Cells(iColumn2).Value)
Next
dDist = dn1n2 / (nSp1 + nSp1)
sRTF &= "<ul class='list-group'>"
sRTF &= "<li class='list-group-item'>Número de indivíduos da amostra " & ODGV.Columns(iColumn1).HeaderCell.Value & ": " & nSp1 & "</li>"
sRTF &= "<li class='list-group-item'>Número de indivíduos da amostra " & ODGV.Columns(iColumn2).HeaderCell.Value & ": " & nSp2 & "</li>"
sRTF &= "<li class='list-group-item'>Distância de Bray-Curtis: " & Math.Round(dDist, 4) & "</li>"
sRTF &= "</ul>"
sResult = sHTMLStart & "<h3 class='alert alert-success'>Distância de Bray-Curtis</h3>" & sRTF & sFooter & sHTMLEnd
Return sResult
Catch ex As Exception
LibError.ErrorView(ex)
Return retError(sHTMLStart, ex, sHTMLEnd)
End Try
End Function
Public Function Manhattan(ByVal ODGV As DataGridView, ByVal iColumn1 As Integer, ByVal iColumn2 As Integer) As String
Dim lRow As Integer = ODGV.RowCount
Dim iR As Integer
Dim nSp1 As Integer, nSp2 As Integer, dn1n2 As Double
Dim sRTF As String = ""
Dim dDist As Double
Try
If Auditoria(ODGV) = False Then
If MsgAuditoria() = False Then
Return sRetAuditoria
Exit Function
End If
End If
For iR = 0 To lRow - 1
If ODGV.Rows(iR).Cells(iColumn1).Value > 0 Then
nSp1 += ODGV.Rows(iR).Cells(iColumn1).Value
End If
If ODGV.Rows(iR).Cells(iColumn2).Value > 0 Then
nSp2 += ODGV.Rows(iR).Cells(iColumn2).Value
End If
dn1n2 += Math.Abs(ODGV.Rows(iR).Cells(iColumn1).Value - ODGV.Rows(iR).Cells(iColumn2).Value)
Next
dDist = dn1n2
sRTF &= "<ul class='list-group'>"
sRTF &= "<li class='list-group-item'>Número de indivíduos da amostra " & ODGV.Columns(iColumn1).HeaderCell.Value & ": " & nSp1 & "</li>"
sRTF &= "<li class='list-group-item'>Número de indivíduos da amostra " & ODGV.Columns(iColumn2).HeaderCell.Value & ": " & nSp2 & "</li>"
sRTF &= "<li class='list-group-item'>Distância de Manhattan: " & Math.Round(dDist, 4) & "</li>"
sRTF &= "</ul>"
sResult = sHTMLStart & "<h3 class='alert alert-success'>Distância de Manhattan</h3>" & sRTF & sFooter & sHTMLEnd
Return sResult
Catch ex As Exception
LibError.ErrorView(ex)
Return retError(sHTMLStart, ex, sHTMLEnd)
End Try
End Function
Public Function Morisita(ByVal ODGV As DataGridView, ByVal iColumn1 As Integer, ByVal iColumn2 As Integer) As String
Dim lRow As Integer = ODGV.RowCount
Dim iR As Integer
Dim nSp1 As Integer, nSp2 As Integer, dn1n2 As Double
Dim sRTF As String = ""
Dim dSimilar As Double, dDisp1 As Double, dDisp2 As Double
Dim dSumX1Doub As Double, dLambda1 As Double
Dim dSumX2Doub As Double, dLambda2 As Double
Dim dSumLamb1 As Double, dSumLamb2 As Double ' soma numeradores
Dim dSumDenLamb1 As Double, dSumDenLamb2 As Double 'soma Denominadores
Dim dMor1 As Double
Dim dValue As String
Try
If Auditoria(ODGV) = False Then
If MsgAuditoria() = False Then
Return sRetAuditoria
Exit Function
End If
End If
For iR = 0 To lRow - 1
dValue = ODGV.Rows(iR).Cells(iColumn1).Value
nSp1 += dValue
dSumX1Doub += dValue ^ 2
If dValue > 1 Then
dSumLamb1 += dValue * (dValue - 1)
dSumDenLamb1 += dValue - 1
End If
dValue = ODGV.Rows(iR).Cells(iColumn2).Value
nSp2 += dValue
dSumX2Doub += dValue ^ 2
If dValue > 1 Then
dSumLamb2 += dValue * (dValue - 1)
dSumDenLamb2 += dValue - 1
End If
dn1n2 += ODGV.Rows(iR).Cells(iColumn1).Value * ODGV.Rows(iR).Cells(iColumn2).Value
Next
dLambda1 = dSumLamb1 / (nSp1 * dSumDenLamb1)
dLambda2 = dSumLamb2 / (nSp2 * dSumDenLamb2)
dMor1 = (2 * dn1n2) / ((dLambda1 + dLambda2) * (nSp1 * nSp2))
dDisp1 = lRow * (dSumX1Doub - nSp1) / ((nSp1 ^ 2) - nSp1)
dDisp2 = lRow * (dSumX2Doub - nSp2) / ((nSp2 ^ 2) - nSp2)
dSimilar = dn1n2
sRTF &= "<ul class='list-group'>"
sRTF &= "<li class='list-group-item'>Número de indivíduos da amostra " & ODGV.Columns(iColumn1).HeaderCell.Value & ": " & nSp1 & "</li>"
sRTF &= "<li class='list-group-item'>Número de indivíduos da amostra " & ODGV.Columns(iColumn2).HeaderCell.Value & ": " & nSp2 & "</li>"
sRTF &= "<li class='list-group-item'>Similaridade de Morisita: " & Math.Round(dMor1, 4) & "</li>"
sRTF &= "<li class='list-group-item'>Dispersão de Morisita amostra " & ODGV.Columns(iColumn1).HeaderCell.Value & ": " & Math.Round(dDisp1, 4) & "</li>"
sRTF &= "<li class='list-group-item'>Dispersão de Morisita amostra " & ODGV.Columns(iColumn2).HeaderCell.Value & ": " & Math.Round(dDisp2, 4) & "</li>"
sRTF &= "</ul>"
sResult = sHTMLStart & "<h3 class='alert alert-success'>Índice de Morisita</h3>" & sRTF & sFooter & sHTMLEnd
Return sResult
Catch ex As Exception
LibError.ErrorView(ex)
Return retError(sHTMLStart, ex, sHTMLEnd)
End Try
End Function
Public Function MorisitaHorn(ByVal ODGV As DataGridView, ByVal iColumn1 As Integer, ByVal iColumn2 As Integer) As String
Dim lRow As Integer = ODGV.RowCount
Dim iR As Integer
Dim nSp1 As Integer, nSp2 As Integer, dn1n2 As Double
Dim sRTF As String = ""
Dim dSimilar As Double
Dim dSumX1Doub As Double, dLambda1 As Double
Dim dSumX2Doub As Double, dLambda2 As Double
Dim dMorHorn As Double
Dim dValue As String
Try
If Auditoria(ODGV) = False Then
If MsgAuditoria() = False Then
Return sRetAuditoria
Exit Function
End If
End If
For iR = 0 To lRow - 1
dValue = ODGV.Rows(iR).Cells(iColumn1).Value
nSp1 += dValue
dSumX1Doub += dValue ^ 2
dValue = ODGV.Rows(iR).Cells(iColumn2).Value
nSp2 += dValue
dSumX2Doub += dValue ^ 2
dn1n2 += (ODGV.Rows(iR).Cells(iColumn1).Value * ODGV.Rows(iR).Cells(iColumn2).Value)
Next
dLambda1 = dSumX1Doub / (nSp1 ^ 2)
dLambda2 = dSumX2Doub / (nSp2 ^ 2)
dMorHorn = (2 * dn1n2) / ((dLambda1 + dLambda2) * (nSp1 * nSp2))
dSimilar = dn1n2
sRTF &= "<ul class='list-group'>"
sRTF &= "<li class='list-group-item'>Número de indivíduos da amostra " & ODGV.Columns(iColumn1).HeaderCell.Value & ": " & nSp1 & "</li>"
sRTF &= "<li class='list-group-item'>Número de indivíduos da amostra " & ODGV.Columns(iColumn2).HeaderCell.Value & ": " & nSp2 & "</li>"
sRTF &= "<li class='list-group-item'>Similaridade de Morisita-Horn: " & Math.Round(dMorHorn, 4) & "</li>"
sRTF &= "</ul>"
sResult = sHTMLStart & "<h3 class='alert alert-success'>Índice de Morisita-Horn</h3>" & sRTF & sFooter & sHTMLEnd
Return sResult
Catch ex As Exception
LibError.ErrorView(ex)
Return retError(sHTMLStart, ex, sHTMLEnd)
End Try
End Function
Public Function SoresenSim(ByVal ODGV As DataGridView, ByVal iColumn1 As Integer, ByVal iColumn2 As Integer) As String
Dim lRow As Integer = ODGV.RowCount
Dim iR As Integer
Dim nSp1 As Integer, nSp2 As Integer, dn1n2 As Double
Dim sRTF As String = ""
Dim dSimilar As Double
Try
If Auditoria(ODGV) = False Then
If MsgAuditoria() = False Then
Return sRetAuditoria
Exit Function
End If
End If
For iR = 0 To lRow - 1
If ODGV.Rows(iR).Cells(iColumn1).Value > 0 Then
nSp1 += 1
End If
If ODGV.Rows(iR).Cells(iColumn2).Value > 0 Then
nSp2 += 1
End If
If ODGV.Rows(iR).Cells(iColumn1).Value > 0 And ODGV.Rows(iR).Cells(iColumn2).Value > 0 Then
dn1n2 += 1
End If
Next
dSimilar = (2 * dn1n2) / (nSp1 + nSp2)
sRTF &= "<ul class='list-group'>"
sRTF &= "<li class='list-group-item'>Número de indivíduos da amostra " & ODGV.Columns(iColumn1).HeaderCell.Value & ": " & nSp1 & "</li>"
sRTF &= "<li class='list-group-item'>Número de indivíduos da amostra " & ODGV.Columns(iColumn2).HeaderCell.Value & ": " & nSp2 & "</li>"
sRTF &= "<li class='list-group-item'>Similaridade de Sorensen (β): " & Math.Round(dSimilar, 4) & "</li>"
sRTF &= "</ul>"
sResult = sHTMLStart & "<h3 class='alert alert-success'>Índice de Similaridade Sorensen</h3>" & sRTF & sFooter & sHTMLEnd
Return sResult
Catch ex As Exception
LibError.ErrorView(ex)
Return retError(sHTMLStart, ex, sHTMLEnd)
End Try
End Function
Public Function Canberra(ByVal ODGV As DataGridView, ByVal iColumn1 As Integer, ByVal iColumn2 As Integer) As String
Dim lRow As Integer = ODGV.RowCount
Dim iR As Integer
Dim nSp1 As Integer, nSp2 As Integer, dn1n2 As Double
Dim sRTF As String = ""
Dim dSimilar As Double
Dim dCel1 As Double, dCel2 As Double
Try
If Auditoria(ODGV) = False Then
If MsgAuditoria() = False Then
Return sRetAuditoria
Exit Function
End If
End If
For iR = 0 To lRow - 1
If ODGV.Rows(iR).Cells(iColumn1).Value > 0 Then
nSp1 += 1
End If
If ODGV.Rows(iR).Cells(iColumn2).Value > 0 Then
nSp2 += 1
End If
If ODGV.Rows(iR).Cells(iColumn1).Value > 0 And ODGV.Rows(iR).Cells(iColumn2).Value > 0 Then
dCel1 = ODGV.Rows(iR).Cells(iColumn1).Value
dCel2 = ODGV.Rows(iR).Cells(iColumn2).Value
dn1n2 += (Math.Abs(dCel1 - dCel2) / (dCel1 + dCel2))
End If
Next
dSimilar = dn1n2 / (nSp1 + nSp2)
sRTF &= "<ul class='list-group'>"
sRTF &= "<li class='list-group-item'>Número de indivíduos da amostra " & ODGV.Columns(iColumn1).HeaderCell.Value & ": " & nSp1 & "</li>"
sRTF &= "<li class='list-group-item'>Número de indivíduos da amostra " & ODGV.Columns(iColumn2).HeaderCell.Value & ": " & nSp2 & "</li>"
sRTF &= "<li class='list-group-item'>Similaridade de Canberra: " & Math.Round(dSimilar, 4) & "</li>"
sRTF &= "</ul>"
sResult = sHTMLStart & "<h3 class='alert alert-success'>Índice de Similaridade Canberra</h3>" & sRTF & sFooter & sHTMLEnd
Return sResult
Catch ex As Exception
LibError.ErrorView(ex)
Return retError(sHTMLStart, ex, sHTMLEnd)
End Try
End Function
End Class