Graph:...orldWS(3pm)

πŸ’– Graph::Maker::SmallWorldWS πŸ’–

okay bestie, sit down, hydrate, because we're about to build a whole small world graph and it's genuinely iconic. this is Graph::Maker::SmallWorldWS, a lil Perl module from the User Contributed Perl Documentation crew, and it does exactly one thing but it does it so well πŸ¦‹


✨ NAME ✨

Graph::Maker::SmallWorldWS β€” creates a small-world graph according to (Newman) Watt and Strogatz πŸ’…

no cap, that's the whole vibe. a small world graph. it's giving "everyone is six handshakes away from everyone else" energy.


🌸 VERSION 🌸

Version 0.01 β€” baby's first release, and she ate πŸŽ€


🫢 SYNOPSIS 🫢

so here's the deal, bestie: this creates a small world graph according to (Newman and) Watt and Strogatz's model. and what does a small world graph even have? two things:

  • it has an approximate power law degree distribution (fancy way of saying the degree distribution is kinda lopsided in a specific math-y way πŸ“ˆ)
  • and it has a high clustering coefficient (aka your friends are also friends with each other, it's a whole group chat situation πŸ’¬)

and here's a detail that lowkey matters: if the graph is directed, then edges are added in both directions to create an undirected graph. so like, she's gonna make it undirected whether you like it or not. periodt.

use strict;
use warnings;
use Graph;
use Graph::Maker;
use Graph::Maker::SmallWorldWS;

my $g = new Graph::Maker('small_world_ws', N => 10, K => 2, PR => .1, undirected => 1);
my $g2 = new Graph::Maker('small_world_ws', N => 10, K => 2, PR => .1, keep_edges => 1, undirected => 1);
# work with the graph

look at that second one β€” keep_edges => 1. she's different. we'll get to her 😌


πŸ”₯ FUNCTIONS πŸ”₯

new %params

creates a small world graph with N nodes, K initial connections, and a probability of rewiring of PR according to Watts and Strogats. (yes, that's how it's spelled in the source, we don't touch it πŸ’€)

here's the full roster of recognized parameters, bestie β€” write these down:

  • N β€” the number of nodes
  • K β€” the initial connections
  • PR β€” the probability of rewiring
  • graph_maker
  • keep_edges

any others are passed onto Graph's constructor. so if you got extra params, they're not lost, they just go hang out with Graph instead. slay.

and now the defaults, because defaults are the lore:

  • if N is not given, it defaults to 0
  • if K is not given, it defaults to 0
  • if PR is not given, it defaults to 0
ok but what's the deal with keep_edges? bestie. keep_edges uses the Newman, Watts and Strogatz model, where "rewiring" adds an edge between two random nodes, instead of removing and then adding. so the classic move is remove then add β€” but with keep_edges she just adds. different model, different girl πŸ’…

and one more: if graph_maker is specified, it will be called to create the Graph class as desired (for example if you have a subclass of Graph). if you don't specify it, this defaults to creating a Graph with the parameters specified. so you can bring your own fancy subclass and she'll use it, no questions asked πŸ‘‘


πŸ‘‘ AUTHOR πŸ‘‘

Matt Spear, "<batman900+cpan at gmail.com>" β€” the legend behind all this. respectfully, icon behavior.


πŸ’€ BUGS πŸ’€

found a bug? a feature request? a whole situation? please report any bugs or feature requests to "bug-graph-maker-smallworldws at rt.cpan.org", or through the web interface at:

<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Graph-Maker>

and here's the cute part: I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. so it's a whole two-way notification pipeline. you're not yelling into the void, bestie, you're yelling into RT and RT yells back 🫢


Copyright 2008 Matt Spear, all rights reserved.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. so like, go wild but respectfully πŸ’œ


and that's the whole page, bestie!! now go make some small world graphs and tell everyone you know. main character energy only ✨

this page is perl v5.32.1, dated 2021-08-27, and it lives in the Graph:...orldWS(3pm) corner of the manual β€” take care of her, she's doing her best πŸŽ€πŸ¦‹πŸ’–

πŸ“¦ where this page comes from