Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgrammingVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old February 16th, 2005, 03:38 AM
leelaaa leelaaa is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2005
Posts: 12 leelaaa User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 h 24 m 50 sec
Reputation Power: 0
This is a Visual basic application

Code:
'////////////////////////////////////////////////////////////
'////////// DO NOT DISTRIBUTE WITHOUT PERMISSION
'////////// Wit C. Bushko 8*833 5674
'////////////////////////////////////////////////////////////
Option Explicit
'
Private Const MIN_DISTX = 0.0001
Private Const MIN_DISTY = 0.0001
'
Private Type LineFit
    A As Double
    b As Double
    x1 As Double
    x2 As Double
    q As Double
End Type
'--------------------------------------------------------------------------------
Public Sub CompressData(RawData() As Double, CompData() As Double, _
                ByVal DistX As Double, ByVal DistY As Double)
'------
' CompressData finds a multilinear fit to a series of points.
' Input:
'   RawData(i,j)  - coordinate x (i=0), and coordinate y,(i=1) of the jth point (j=0,1,2,...,n)
'                   of raw data.
'   DistX         - parameter defining the accuracy of x coordinate fit.
'   DistY         - parameter defining the accuracy of y coordinate fit.
' Output:
'   CompData(i,j) - coordinate x (i=0), and coordinate y,(i=1) of jth point (j=0,1,2,...,n)
'                   of compressed data.
'
'------
    Dim n1 As Long
    Dim n2 As Long
    Dim n, Mx As Long
    Dim A As Double
    Dim b As Double
    Dim Seg() As LineFit
    Dim i As Integer
    Dim y1, y2, ymax, ymin As Double
    Dim NorD As Double
'---
    If DistX < MIN_DISTX Then DistX = MIN_DISTX
    If DistY < MIN_DISTY Then DistX = MIN_DISTY
'
    Mx = UBound(RawData, 2)
'
    n = -1
    n1 = 0
    Do
        LinearFit RawData(), n1, n2, DistX, DistY, A, b, NorD
'
        n = n + 1: ReDim Preserve Seg(n)
        Seg(n).A = A
        Seg(n).b = b
        Seg(n).x1 = RawData(0, n1)
        Seg(n).x2 = RawData(0, n2)
        Seg(n).q = NorD
        If n2 = Mx Then Exit Do
        n1 = n2
    Loop
'-------
    ReDim CompData(1, n + 1)
    CompData(0, 0) = Seg(0).x1
    CompData(1, 0) = Seg(0).A * Seg(0).x1 + Seg(0).b
    For i = 1 To n
        CompData(0, i) = Seg(i).x1
        y1 = Seg(i - 1).A * CompData(0, i) + Seg(i - 1).b + Seg(i - 1).q
        y2 = Seg(i).A * CompData(0, i) + Seg(i).b + Seg(i).q
        If y1 < y2 Then ymax = y1 Else ymax = y2
        y1 = Seg(i - 1).A * CompData(0, i) + Seg(i - 1).b - Seg(i - 1).q
        y2 = Seg(i).A * CompData(0, i) + Seg(i).b - Seg(i).q
        If y1 > y2 Then ymin = y1 Else ymin = y2
        CompData(1, i) = (ymin + ymax) / 2#
    Next
    CompData(0, n + 1) = Seg(n).x2
    CompData(1, n + 1) = Seg(n).A * Seg(n).x2 + Seg(n).b
'---
End Sub
'--------------------------------------------------------------------------------
Private Sub LinearFit(y() As Double, nmin As Long, nmax As Long, _
                ByVal DistX As Double, ByVal DistY As Double, _
                A As Double, b As Double, NorD As Double)
'---
    Dim Flg As Boolean
    Dim i, n1, n2, Mx, m, Dn, q As Long
    Dim Sx, Sxx, Sy, Sxy As Double
    Dim MaxD As Double
'---
    Mx = UBound(y, 2)
'
    Sx = y(0, nmin): Sxx = y(0, nmin) * y(0, nmin)
    Sy = y(1, nmin)
    Sxy = y(0, nmin) * y(1, nmin)
'
    nmax = nmin
    Dn = 1
    n1 = nmax + 1
    nmax = nmax + Dn
    n2 = nmax
    q = 1
'-------
    Do
        For i = n1 To n2
            Sx = Sx + q * y(0, i): Sxx = Sxx + q * y(0, i) * y(0, i)
            Sy = Sy + q * y(1, i)
            Sxy = Sxy + q * y(0, i) * y(1, i)
        Next
        m = nmax - nmin + 1
        A = (m * Sxy - Sx * Sy) / (m * Sxx - Sx * Sx)
        b = (Sxx * Sy - Sx * Sxy) / (m * Sxx - Sx * Sx)
'-------
        NorD = Sqr(DistX * DistX * A * A + DistY * DistY)
        MaxD = MaxDistance(y(), nmin, nmax, A, b)
'-------
        If NorD > MaxD Then
            If Flg Then
                If Dn = 1 Then Exit Sub
                Dn = Dn / 2
            Else
                Dn = 2 * Dn
                Do While nmax + Dn > Mx
                    If Dn = 1 Then Exit Sub
                    Dn = Dn / 2
                Loop
            End If
            n1 = nmax + 1
            nmax = nmax + Dn
            n2 = nmax
            q = 1
        Else
            Flg = True
            If Dn > 1 Then Dn = Dn / 2
            n2 = nmax
            nmax = nmax - Dn
            n1 = nmax + 1
            q = -1
        End If
    Loop
'---
End Sub
'--------------------------------------------------------------------------------
Private Function MaxDistance(f() As Double, _
                                n1 As Long, n2 As Long, _
                                A As Double, b As Double) As Double
'---
    Dim i As Integer
    Dim d As Double
'---
    MaxDistance = 0#
    For i = n1 To n2
        d = Abs(A * f(0, i) + b - f(1, i))
        If d > MaxDistance Then MaxDistance = d
    Next
'---
End Function
'--------------------------------------------------------------------------------


This is the code for the compressing a data that is xand y axis and chart is created from compressed data
But i am new to vba i am not able to understand the code can u explain me and i also want a guide for
createing a code for single x axis and multiple y axis.

Last edited by Memnoch : February 16th, 2005 at 09:26 AM.

Reply With Quote
  #2  
Old February 16th, 2005, 09:30 AM
Memnoch's Avatar
Memnoch Memnoch is offline
Unholy Moderator
ASP Free God 14th Plane (11500 - 11999 posts)
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,776 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 8 h 27 m 42 sec
Reputation Power: 470
1) It's not VBA, it VB.

2) Did it come with any type of documentation or read me file?

3) It would be too complicated trying to explain this to you.

4) Work within your skill level, gain experience, then you can advance to more complicated code such as this, but if you can't read the code and understand what is going on, then you'll need to get more familiar with VB.

Reply With Quote
  #3  
Old February 16th, 2005, 09:40 AM
Darius Darius is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Sep 2004
Posts: 108 Darius User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 16 m 54 sec
Reputation Power: 5
I don't know what you mean, you mean y=f(x1,x2,x3)?

if so: It's better to use a matrix solving application, just because simple regresion is easy the matrix aproach is not used, but if you want it for several x's you will need it.

The code without to much deep, looks like:

CompressData: Makes all the stuff (the administrator or main function)
* lineal regresion and maximum difference between data and the model
* compress data (or at least it suppouse to do it in order to have a meaning in the sub name)

LinearFit: Makes regresion and call MaxDistance

MaxDistance: obtain maximum difference between data and the model

Reply With Quote
Reply

Viewing: ASP Free ForumsProgrammingVisual Basic Programming > This is a Visual basic application


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT