Recent Posts

Pages: [1] 2 3 ... 10
1
AutoLISP (Vanilla / Visual) / Re: most common value in a list (mode)
« Last post by Lee Mac on Today at 07:05:33 AM »
Since you're already shortening the list using vl-remove-if with each iteration, it's more efficient to iterate until the list is exhausted rather than using a fixed iteration over the entire original list, e.g.:
Code - Auto/Visual Lisp: [Select]
  1. (defun mode ( lst fuz / cnt dif itm len rtn )
  2.     (while lst
  3.         (setq len (length lst)
  4.               itm (car lst)
  5.               lst (vl-remove-if '(lambda ( x ) (equal itm x fuz)) (cdr lst))
  6.               dif (- len (length lst))
  7.         )
  8.         (if (< cnt dif)
  9.             (setq cnt dif rtn itm)
  10.         )
  11.     )
  12.     rtn
  13. )
Code - Auto/Visual Lisp: [Select]
  1. Benchmarking .............Elapsed milliseconds / relative speed for 1024 iteration(s):
  2.  
  3.     (MODE L 0.01)......1782 / 2.49 <fastest>
  4.     (@MODE L 0.01).....4437 / 1.00 <slowest>
2
AutoLISP (Vanilla / Visual) / Re: most common value in a list (mode)
« Last post by hmspe on Today at 12:08:35 AM »
Sorry, no time to look at code but what happens in the following situation?

11, 11, 33, 33, 54

Should be: (11, 33)
My most recent post will return 11.  My understanding is that the mode would be undefined for your data set because there is not a single number with the highest count in the data set. 

I'm working with distances between adjacent points in an x,y array that come from an ssget operation.  My data set will always have only one most common value.
3
AutoLISP (Vanilla / Visual) / Re: most common value in a list (mode)
« Last post by JohnK on May 30, 2024, 10:59:28 PM »
Sorry, no time to look at code but what happens in the following situation?

11, 11, 33, 33, 54

Should be: (11, 33)
4
AutoLISP (Vanilla / Visual) / Re: most common value in a list (mode)
« Last post by hmspe on May 30, 2024, 10:31:25 PM »
I found an old function by John Uhden in the Autocad forums and modified it slightly.  I changed a couple of single character variables to meaningful names and I return a value instead of a list containing all the instances of the most common value. 

Code - Auto/Visual Lisp: [Select]
  1. (defun @mode (lst fuzz / index count item items mode)
  2.   (setq index 0
  3.         count 0
  4.   )
  5.   (repeat (length lst)
  6.     (setq item (nth index lst)
  7.           items (vl-remove-if-not '(lambda (x)(equal x item fuzz)) lst)
  8.           index (1+ index)
  9.     )
  10.     (if (> (length items) count)
  11.       (setq count (length items) mode items)
  12.     )
  13.   )
  14.   (car mode)
  15. )
  16.  

Test:
Code - Auto/Visual Lisp: [Select]
  1. (defun c:tx ()
  2.   (setq l (list 1.0 5.6 9.3.5 6.6 3 4 8 7 6 2 1 3 5 4 56 8 45 123 545 1 235 15 35 135 1 5 6 7 8 9.3 9.3 9.3 9.3 9.3 9.3 9.3 9.3 9.3 5 1 2 2))
  3.   (print (@mode l  0.01))
  4.   (princ)
  5. )
  6.  

Returns:
9.3

Thanks for the suggestions.
5
AutoLISP (Vanilla / Visual) / Re: most common value in a list (mode)
« Last post by rayakmal on May 30, 2024, 09:41:43 PM »
Welcome back, YMG.

Just use count items by Lee Mac

6
AutoLISP (Vanilla / Visual) / Re: most common value in a list (mode)
« Last post by ymg on May 30, 2024, 09:30:34 PM »
From https://www.investopedia.com/terms/m/mode.asp#:~:text=The%20mode%20in%20statistics%20refers,the%20numbers%20in%20the%20set.

The Bottom Line:
In statistics, the mode is the number that occurs most often. A data set can have one or more modes. The mode is different from the mean, which is the average of the numbers in a set; it's also different from the median, which is the midpoint of a set. Finding the mode in a set of numbers can tell you which data points occur most commonly, which can be useful information when analyzing statistics.


Just use count items by Lee Mac

Code: [Select]
;; Count Items  -  Lee Mac
;; Returns a list of dotted pairs detailing the number of
;; occurrences of each item in a supplied list.

(defun LM:CountItems ( l / c x )
    (if (setq x (car l))
        (progn
            (setq c (length l)
                  l (vl-remove x (cdr l))
            )
            (cons (cons x (- c (length l))) (LM:CountItems l))
        )
    )
)

Examples:

Code: [Select]
(LM:CountItems '("A" "B" "B" "B" "C" "C" "D" "E" "E" "E" "E"))
=>  (("A" . 1) ("B" . 3) ("C" . 2) ("D" . 1) ("E" . 4))


(LM:CountItems '(1 2 3 3 3 4 5 6 6 7 8 8 8 8))
=>  ((1 . 1) (2 . 1) (3 . 3) (4 . 1) (5 . 1) (6 . 2) (7 . 1) (8 . 4))
7
.NET / Re: Previews or Thumbnails
« Last post by It's Alive! on May 30, 2024, 09:25:46 PM »
One last thing, if you’re going to reuse these in a GUI. You may wish to store the images in a SQL database
In SQLite you can store them as a blob, it’s wicked fast (Boston accent)  :lmao:
I store a timestamp, name, path, and image as a blob
8
.NET / Re: Previews or Thumbnails
« Last post by It's Alive! on May 30, 2024, 09:18:40 PM »
Here a version in Python if your feeling adventurous  :mrgreen:
https://www.theswamp.org/index.php?topic=59527.msg621035#msg621035
9
.NET / Re: Previews or Thumbnails
« Last post by It's Alive! on May 30, 2024, 09:06:35 PM »
It’s not a trivial task, but you could try to unpack the .NET BlockView sample.
From there you can grab View.GetSnapShot, which returns a bitmap.
10
.NET / Re: Previews or Thumbnails
« Last post by It's Alive! on May 30, 2024, 09:01:13 PM »
Code - C#: [Select]
  1. using (Database db = new Database(false, true))
Is opening the drawing, so we have some ambiguity on this definition.

If we are good with opening the db, you would pass in the objectid that represents the block table record for the space
Either modelspace or paperspace   
Pages: [1] 2 3 ... 10